SQL Subqueries

I don't think I've ever used cross join :o. What seems to happen is cross join would therefore select every user, and add to it every user_desc; there's no actual link between the two so you couldn't work out what job the user had.

I.e.:

Users
Code:
name                                               staffnumber
-------------------------------------------------- -----------
John                                               1000002
Bananaman                                          1000005

Users_Desc:
Code:
staffnumber job
----------- --------------------------------------------------
1000002     Engineer
1000005     Superhero

Cross join result:
Code:
name                                               staffnumber staffnumber job
-------------------------------------------------- ----------- ----------- --------------------------------------------------
John                                               1000002     1000002     Engineer
Bananaman                                          1000005     1000002     Engineer
John                                               1000002     1000005     Superhero
Bananaman                                          1000005     1000005     Superhero

Notice that each user is duplicated as it contains rows for all jobs.

With an inner join:
Code:
name                                               staffnumber staffnumber job
-------------------------------------------------- ----------- ----------- --------------------------------------------------
John                                               1000002     1000002     Engineer
Bananaman                                          1000005     1000005     Superhero



http://weblogs.sqlteam.com/jeffs/jeffs/archive/2005/09/12/7755.aspx
http://en.wikipedia.org/wiki/Join_(SQL)
 
Back
Top Bottom