Reputation: 104
I have two tables (A & B) my objective is to have some columns from A left joined with a few columns of B (both tables have a LOT of columns)
is it faster to :
A) Select A -> left join -> subselect B: (selecting only the desired columns BEFORE the join)
SELECT * FROM (
SELECT A.col_1,A.col_2,A.col3,A.col_b FROM A
LEFT JOIN (
SELECT B.col_1,B.col_2,B.col_a FROM B) B_temp
ON A.col_b = B_temp.col_a
B) Select A -> left join -B: (selecting only the desired columns AFTER the join)
SELECT A.col_1,A.col_2,A.col3,B.col_1,B.col_2 FROM A
LEFT JOIN B
ON A.col_b = B_temp.col_a
My gut tells me even tho the second option is way more readable, it might be worse since it first aglutinates everything moving a lot of data around. My consideration for this is:
Am I going in the right-way towards optimizing this sql query ?
Upvotes: 0
Views: 64
Reputation: 108641
Unless your SQL software is old and moldy, its query planner will handle your two example queries the same way.
Upvotes: 1