A performance question in select statement

This is a discussion on A performance question in select statement within the MySQL Database forums, part of the Database Forums category; In response to my last question, Captain Paralytic send a diferente select statement to me. My own select was like ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-15-2007
rics
 
Posts: n/a
Default A performance question in select statement

In response to my last question, Captain Paralytic send a diferente
select statement to me. My own select was like this:


SELECT u.id, u.usuario, g.grupo
FROM usuarios u, grupos g, usuarios_grupos ug
WHERE u.id = ug.usuario_id AND g.id = ug.grupo_id


The select of Captain Paralytic was like this:


SELECT u.id, u.usuario, g.grupo
FROM usuarios_grupos ug
JOIN usuarios u ON ug.usuario_id = u.id
JOIN grupos g ON ug.grupo_id = g.id


They return exactly the same results, so my question now is: Is there
any performance issue that I'm missing, or the two statements are
pretty much the same? Is all about syntax only? Which aproach is
better??? Why???

Reply With Quote
  #2 (permalink)  
Old 03-15-2007
Captain Paralytic
 
Posts: n/a
Default Re: A performance question in select statement

On 15 Mar, 14:40, "rics" <ricardo.ce...@gmail.com> wrote:
> In response to my last question, Captain Paralytic send a diferente
> select statement to me. My own select was like this:
>
> SELECT u.id, u.usuario, g.grupo
> FROM usuarios u, grupos g, usuarios_grupos ug
> WHERE u.id = ug.usuario_id AND g.id = ug.grupo_id
>
> The select of Captain Paralytic was like this:
>
> SELECT u.id, u.usuario, g.grupo
> FROM usuarios_grupos ug
> JOIN usuarios u ON ug.usuario_id = u.id
> JOIN grupos g ON ug.grupo_id = g.id
>
> They return exactly the same results, so my question now is: Is there
> any performance issue that I'm missing, or the two statements are
> pretty much the same? Is all about syntax only? Which aproach is
> better??? Why???


If you do an explain on the 2 selects you will find that in this case
they are likely to be identical.

My proposed query was more obvious in its intentions. Also, my one can
easily be altered to use LEFT JOINs should the need arrive.

I used to write all joins as you had and asked a similar question to
this one on this very newsgroup. I have now spent so long using the
JOIN syntax that I find it hard to figure out at a glance what the
other syntax is doing.

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:57 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0