The queries are the same except potentially the second won't use index if any exists on grade_* columns. And this flipped approach Is rather uncommon (at least i see it for first time). Possibly because you wouldnt need such approach if you had a better tables structure.
What if suddently students can study history or biology? You Will need to create new ...
Oh well, I didnt notice the sql-server tag...
What a detailed execution plan they have :)
But anyway the answer may be as simple as that there is more answers than there are questions.
And because you are making another subselect for the column and you are selecting what you already have in the outer select, this may get expensive quite fast.
So I would ...
I defined the fields that I wanted to be required first. Then, I defined a One-to-Many relationship between an account table and a contacts table where the contact id is the account's name in the account's table in the SQL database
$account = new Account();
$mapping = $request->$mapping;
$account->name = $...
You write this is a
however that is not true. It's a function that
executes an SQL query
converts its result set to a string
(sometimes) closes its DB connection
Generally its bad idea to have a function to do more than one thing. Especially the closing of a DB connection that (I presume) is ...