by heru on August 27, 2011
Your time is limited. Don’t waste it living someone else’s life.
Because the people who are crazy enough to think they can change the world, are the ones who do.
Steve Jobs. Thank you.
by heru on August 27, 2011
Query #1:
2
| SELECT * FROM a, b WHERE a.b_id = b.id AND b.id > 0; |
vs
Query #2:
2
| SELECT * FROM a INNER JOIN b ON a.b_id = b.id AND b.id > 0; |
- Are they the same?
- Do they produce the same result?
- Which query runs faster?
The third one is actually a trick question. The answer for #1 and #2 is that technically both are the same. I have found this out of curiosity after doing an interview with fresh graduates that have the habit of using INNER JOIN instead of =.
After researching through, I found out that
a thread in stack overflow discusses this in pretty details. Please make sure your read other answers as well!
Basically in summary from StackOverflow:
- #2 is easier to read when you have multiple tables involved.
- #2 is safer because #1 if you miss the ‘=’, then it will cause a cartesian join (which in 2 large tables, it will be very painful!
I am found guilty that I am a habitual practice of #1. I think it is time to break my old habit and adapt a new one.