1

Query 1.

select friends.name,social.facebook   
from friends inner join social on friends.id=social.fid where facebook="Yes";

Output.

+-----------------+
| name | facebook |
+-----------------+
| ABC  |   Yes    |
| BCD  |   Yes    |
| CDE  |   Yes    |
+-----------------+

Query 2.

select f.name,s.facebook from friends as f,social as s   
where f.id=s.fid && s.facebook="Yes";

Output.

+-----------------+
| name | facebook |
+-----------------+
| ABC  |   Yes    |
| BCD  |   Yes    |
| CDE  |   Yes    |
+-----------------+

Which way is more reliable and fast?

Luthando Ntsekwa
  • 4,192
  • 6
  • 23
  • 52
Rahul
  • 111
  • 10

2 Answers2

1

I would say Query1 is ANSI compliant and advisable. Query2 becomes cross join if you omit the WHERE condition thus providing unwanted data. In Query1, if JOINed columns are not specified you get an error which is more reliable

Madhivanan
  • 13,470
  • 1
  • 24
  • 29
  • MySQL doesn't give an error message if you leave out the `ON` clause. It just treats it like `CROSS JOIN`. – Barmar Sep 04 '15 at 11:49
1

No difference on result set wise but your first query as below is using ANSI style explicit join syntax

select friends.name,social.facebook 
from friends inner join social on friends.id=social.fid 
where social.facebook="Yes"; //also qualify the column with alias/table name

whereas second query as below is using old style implicit join syntax.

select f.name,s.facebook from friends as f,social as s 
where f.id=s.fid && s.facebook="Yes"

Prefer the first style of JOIN since it's more readable and clears your intention.

Rahul
  • 76,197
  • 13
  • 71
  • 125