Reputation: 35
I'm just curious, if i have table a and table b.
I write query 1:
SELECT * FROM table a INNER JOIN table b ON table a.id = table b.id
I write query 2:
SELECT * FROM table b INNER JOIN table a ON table b.id = table a. id
What is the difference both of above query?
Thank you
Upvotes: 2
Views: 83
Reputation: 28751
When using INNER JOIN
, there is no difference in resultset returned except in order of columns when SELECT *
is used i.e. columns are not explicitly mentioned.
SELECT *
FROM table a
INNER JOIN table b
ON table a.id = table b.id
returns columns from tableA followed by columns from tableB
SELECT *
FROM table b
INNER JOIN table a
ON table b.id = table a. id
returns columns from tableB followed by columns from tableA
Upvotes: 2
Reputation: 3108
The second table matches data with the first one. So it is better to put smaller table on the second place.
Upvotes: 0