On Fri, Nov 22, 2002 at 06:56:53PM -0500, Michael T. Babcock wrote:
> On Fri, Nov 22, 2002 at 06:20:14PM -0500, Philip Mak wrote:
> > sql,query
> >
>
> Why not just:
> SELECT * FROM users, boardAdmins, boardMembers WHERE id = 5;
>
> You're not really 'joining', since boardAdmins and boardMembers
> don't have the structure JOINs are made for (it seems).
Oops! I was typing my example from memory, and did it wrong.
Sorry, it's supposed to be like this:
SELECT *
FROM boards
LEFT JOIN boardAdmins
ON boardAdmins.userId = #{userId}
AND boardAdmins.boardId = boards.id
LEFT JOIN boardMembers
ON boardMembers.userId = #{userId}
AND boardMembers.boardId = boards.id
AND boards.id = #{boardId}
For each entry in "boards", there are zero or more corresponding
entries in boardAdmins and boardMembers.
The above could be rewritten with 3 separate SELECT statements:
SELECT *
FROM boards
WHERE id = #{boardId}
SELECT *
FROM boardMembers
WHERE userId = #{userId}
AND boardId = #{boardId}
SELECT *
FROM boardAdmins
WHERE userId = #{userId}
AND boardId = #{boardId}
So, I'm wondering which way would be faster.
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php