equi-join VS JOIN or INNER JOIN

  • Follow


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.
0
Reply don.orban (20) 1/23/2008 3:42:04 PM

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.
1
Reply Captain 1/23/2008 4:14:04 PM


1 Replies
813 Views

(page loaded in 0.06 seconds)

Similiar Articles:













7/22/2012 9:18:15 AM


Reply: