1

Having the following SQL

SELECT 
    u.user_id     AS user_id, 
    u.user_name   AS user_name,
    d.user_data   AS user_data 
FROM 
    tbl_users u, 
    tbl_data  d        
WHERE 
    d.user_id = u.user_id

Does this still produces a JOIN (as there's no JOIN keyword in this sql)? How does MySQL handle this query?

And is there any difference if the WHERE clause would be u.user_id = d.user_id instead of d.user_id = u.user_id ?

Thanks.

1
  • 1
    You've got two tables in the FROM clause, and are relating them in the WHERE clause - it's a JOIN in disguise. Commented Jun 15, 2011 at 22:02

4 Answers 4

3

What you're writing is the old style SQL syntax before ANSI standardized the JOIN keywords back in 1992.

With a simple query like what you're writing above, most RDBMS's will internally convert it to the same lookup method as an inner join.

As for the order of the columns in the where clause, the only time it matters is when you have a derived column, or a function. Generally you would want to keep the non-derived or non-functional column first, in that case, so that the engine can figure out the correct index to use.

Sign up to request clarification or add additional context in comments.

Comments

2

yes this is an alternate (older) syntax for joining.

It is still perfectly valid. The order of the AND conditions does not matter.

1 Comment

i write queries this way all the time... since i'm old :)
1

Your query gives the same result as one where you did an INNER JOIN.

And there is no difference in order for the WHERE clause.

Comments

1

Yes, this implicitly tells MySQL to do an inner join, it's equivalent to:

SELECT 
    u.user_id     AS user_id, 
    u.user_name   AS user_name,
    d.user_data   AS user_data 
FROM 
    tbl_users u
    INNER JOIN
        tbl_data  d
    ON
        d.user_id = u.user_id

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.