Go Back   Forum Care Forums > Development Reference Area > MySQL Discussion

Reply
 
LinkBack Thread Tools Display Modes
possible bad habit from a self-taught novice
Old
  (#1)
Guest
Guest
 
Posts: n/a
Default possible bad habit from a self-taught novice - 06-04-2007, 07:58 AM

I usually do implied 'comma' joins like this:

select username,users.user_id,EVENT_ANNOUNCE_EMAIL from
users,user_settings WHERE users.user_id=user_settings.user_id AND
users.user_id=1;

which I believe is equivalent to this:

select username,users.user_id,EVENT_ANNOUNCE_EMAIL from users JOIN
user_settings ON users.user_id=user_settings.user_id WHERE
users.user_id=1;

EXPLAIN gives the same results in this case.

It seems to me it is not good practice to mix the join condition and
the where clause together like I have been, and I am wondering if a)
there is a functional difference, and b) if it is acceptable practice
and I am just retentive.

thanx

   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: possible bad habit from a self-taught novice
Old
  (#2)
Captain Paralytic
Guest
 
Posts: n/a
Default Re: possible bad habit from a self-taught novice - 06-04-2007, 07:58 AM

On 20 May, 18:12, christop...@dailycrossword.com wrote:
> I usually do implied 'comma' joins like this:
>
> select username,users.user_id,EVENT_ANNOUNCE_EMAIL from
> users,user_settings WHERE users.user_id=user_settings.user_id AND
> users.user_id=1;
>
> which I believe is equivalent to this:
>
> select username,users.user_id,EVENT_ANNOUNCE_EMAIL from users JOIN
> user_settings ON users.user_id=user_settings.user_id WHERE
> users.user_id=1;
>
> EXPLAIN gives the same results in this case.
>
> It seems to me it is not good practice to mix the join condition and
> the where clause together like I have been, and I am wondering if a)
> there is a functional difference, and b) if it is acceptable practice
> and I am just retentive.
>
> thanx


a) There is no functional difference, but it is neither as clear nor
as felxible as using the JOIN verb. Writing it as:
SELECT
`username`,
`users`.`user_id`,
`EVENT_ANNOUNCE_EMAIL`
FROM `users`
JOIN `user_settings` ON USING (`user_id`)
WHERE `users`.`user_id`=1;
tells one which fields do what. I tend to also qualify all the fields,
usually using aliases, so that it is also obviousl what field comes
from what table. Looking at your query, I have no idea which table
username or EVENT_ANNOUNCE_EMAIL is in. Note that I set teh query out
in such a way that I can immediately see what the query contains. I
don't have to go searching in a m*** of text.

b) Depends who is accepting it. I used to mix comma joins with others,
but now I favour clarity.

   
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

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





Contact Us - Forum Care Forums - Archive - Top