Query difference: Grouped JOIN vs inline JOIN

I have two different queries which return the same data:

+---------+-------------------------------+----------+
| title   | body                          | username |
+---------+-------------------------------+----------+
| Welcome | You got a cool forum here     | john     |
| Welcome | Great topics.                 | boyd     |
| Welcome | Nice to have you as members   | cris     |
| Looking | I have the time and knowlegde | boyd     |
| Looking | I'm fully qualified for this  | joe      |
+---------+-------------------------------+----------+

Query I:

SELECT posts.title,comments.body,users.username
FROM posts
    LEFT JOIN (
        users INNER JOIN comments ON users.id = comments.user_id
    ) ON posts.id = comments.post_id

Query II:

SELECT posts.title,comments.body,users.username
FROM posts
    LEFT JOIN comments ON posts.id = comments.post_id
    INNER JOIN users  ON users.id = comments.user_id

And these are my tables:

    USERS
+----+----------+
| id | username |
+----+----------+
|  1 | john     |
|  2 | boyd     |
|  3 | ella     |
|  4 | cris     |
|  5 | joe      |
|  6 | esses    |
| 18 | test2    |
+----+----------+
            POSTS
+----+-----------------------+
| id | title                 |
+----+-----------------------+
|  1 | Welcome               |
|  2 | Looking for moderator |
+----+-----------------------+

                        COMMENTS
+---------+---------+------------------------------------------+
| post_id | user_id | body                                     |
+---------+---------+------------------------------------------+
|       1 |       1 | You got a cool forum here                |
|       1 |       2 | Great topics.                            |
|       1 |       4 | Nice to have you as members              |
|       2 |       2 | I have the time and knowlegde to do this |
|       2 |       5 | I'm fully qualified for this job         |
+---------+---------+------------------------------------------+

My question is: Whats the real difference between these two queries?


Source: sql

Leave a Reply