Unix Technical Forum

equi-join VS JOIN or INNER JOIN

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 ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 11:32 AM
DonO
 
Posts: n/a
Default equi-join VS JOIN or INNER JOIN

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 11:32 AM
Captain Paralytic
 
Posts: n/a
Default Re: equi-join VS JOIN or INNER JOIN

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:41 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com