Which method is better to go into mysql tables?

What is the difference between these two methods of selecting data from multiple tables. The first does not use JOIN while the second does. What is the preferred method?

Method 1:

SELECT t1.a, t1.b, t2.c, t2.d, t3.e, t3.f FROM table1 t1, table2 t2, table3 t3 WHERE t1.id = t2.id AND t2.id = t3.id AND t3.id = x 

Method 2:

 SELECT t1.a, t1.b, t2.c, t2.d, t3.e, t3.f FROM `table1` t1 JOIN `table2` t2 ON t1.id = t2.id JOIN `table3` t3 ON t1.id = t3.id WHERE t1.id = x 
+4
source share
3 answers

For your simple case, they are equivalent. Despite the fact that the keyword โ€œJOINโ€ is not present in method # 1, it still performs joins.

However, method # 2 offers the flexibility to provide additional JOIN conditions that cannot be met using WHERE clauses. For example, when you make aliases with several aliases against one table.

 select a.id, b.id, c.id from sometable A left join othertable as b on a.id=b.a_id and some_condition_in_othertable left join othertable as c on a.id=c.a_id and other_condition_in_othertable 

The inclusion of two additional conditions in the whereclause will cause the query to return nothing, since both conditions cannot be true at the same time in the where clause, but are possible in the connection.

+2
source

The methods are obviously identical in performance , it's just the new and old syntax.

0
source

I donโ€™t think there is a big difference. You can use the EXPLAIN statement to check if MySQL is doing something different. For this trivial example, I doubt it is important.

-1
source

All Articles