This is a discussion on equi-join VS JOIN or INNER JOIN within the MySQL forums, part of the Database Server Software category; --> If I have tables like so (just an example)... AUTHOR id name BOOK id title author_id And want to ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| If I have tables like so (just an example)... AUTHOR id name BOOK id title author_id And want to get a listing of all books and their authors (not worried about outer joins here), I can do either of these... SELECT b.title, a.name FROM book b, author a WHERE b.author_id = a.id or, I can do... SELECT b.title, a.name FROM book b JOIN author a ON b.author_id = a.id Is there any advantage of one over the other? I thought the latter was supposed to be more "right" since I've been discouraged from using the former when I've posted in the past, but when I look at the MySQL docs, it looks like "equi-joins" are perfectly acceptable, and from what I read somewhere else, may work better in an a=b/b=a situation. I'm curious if anyone has a solid reason for using one or the other. My habits were picked up from coworkers as I was learning how to build SQL statements, so other than, "that's how I've always done it" I don't have a strong reasoning behind my methodology. Thanks, D. |
| ||||
| On 23 Jan, 15:42, DonO <don.or...@gmail.com> wrote: > If I have tables like so (just an example)... > > AUTHOR > id > name > > BOOK > id > title > author_id > > And want to get a listing of all books and their authors (not worried > about outer joins here), I can do either of these... > > SELECT b.title, a.name > FROM book b, author a > WHERE b.author_id = a.id > > or, I can do... > > SELECT b.title, a.name > FROM book b > JOIN author a ON b.author_id = a.id > > Is there any advantage of one over the other? I thought the latter was > supposed to be more "right" since I've been discouraged from using the > former when I've posted in the past, but when I look at the MySQL > docs, it looks like "equi-joins" are perfectly acceptable, and from > what I read somewhere else, may work better in an a=b/b=a situation. > > I'm curious if anyone has a solid reason for using one or the other. > My habits were picked up from coworkers as I was learning how to build > SQL statements, so other than, "that's how I've always done it" I > don't have a strong reasoning behind my methodology. > > Thanks, > D. For a simple join like that, MySQL will perform exactly the same join for both cases. The latter case makes it clearer what is happening, makes it easier to add LEFT JOINS, and keeps the priorities sorted out. |