I have been using MySQL for 2 years now, yet I still don’t know what you actually do with the JOIN statement. I really didn’t come across any situation where I was unable to solve a problem with the statements and syntax I already know (SELECT, INSERT, UPDATE, ordering, …)
- What does JOIN do in MySQL?
- (Where) Do I need it?
- Should I generally avoid it?
You’ve probably been using it without knowing it, if you’ve ever queried more than one table at a time.
If you do a query like
Then you are, in fact, doing a join (an INNER JOIN) even though you aren’t using the JOIN keyword.
(Aside: the query above is the equivalent of
)
If all you do are INNER JOINS, then you don’t need to use the JOIN keyword, though it can make what you’re doing more clear.
However, there are other useful types of joins (see the tutorial XpiritO linked, for example), and they are worth understanding.