In your second SELECT you do not select any column from subject_assignment
. Instead, you're selecting single string value made from concatenated column names. And you're selecting it as many times as the row count of subject_assignment
.
UPDATE:
If you want to dynamically create column names and then select data from them, see this: https://stackoverflow.com/a/17573774/925196