satis
8-19-09, 04:54 PM
ok, so just curious what people think.... which way is better to write a multi-table join?
1:
SELECT a.rowid, a.id
FROM queueUsers a
JOIN queueTypes b
on a.type = b.userType
JOIN queue c
on b.rowid = c.queuetype
and c.rowid = 3
JOIN queueUserAccess d
on a.access = d.accessid
and d.description = 'user'
2:
SELECT a.rowid, a.id
FROM queueUsers a
JOIN queueTypes b
on a.type = b.userType
JOIN queue c
on b.rowid = c.queuetype
JOIN queueUserAccess d
on a.access = d.accessid
WHERE c.rowid = 3
AND d.description = 'user'
They're both valid and they both work. One just puts all the conditional items into the where clause and the other in the join statements. The only thing that would change programmatically is c.rowid... I guess I could see the argument for putting that into a trailing where clause and the d.description into the JOIN. Anyway, just curious if anyone has an opinion.
1:
SELECT a.rowid, a.id
FROM queueUsers a
JOIN queueTypes b
on a.type = b.userType
JOIN queue c
on b.rowid = c.queuetype
and c.rowid = 3
JOIN queueUserAccess d
on a.access = d.accessid
and d.description = 'user'
2:
SELECT a.rowid, a.id
FROM queueUsers a
JOIN queueTypes b
on a.type = b.userType
JOIN queue c
on b.rowid = c.queuetype
JOIN queueUserAccess d
on a.access = d.accessid
WHERE c.rowid = 3
AND d.description = 'user'
They're both valid and they both work. One just puts all the conditional items into the where clause and the other in the join statements. The only thing that would change programmatically is c.rowid... I guess I could see the argument for putting that into a trailing where clause and the d.description into the JOIN. Anyway, just curious if anyone has an opinion.