NYCPHP Meetup

NYPHP.org

[nycphp-talk] SQL question

Michael Southwell michael.southwell at nyphp.com
Mon Jul 23 23:30:30 EDT 2007


At 11:08 PM 7/23/2007, you wrote:
Going back to that original query, you can write it like this:

>SELECT cupssbmain.StoryboardID AS sbid
>FROM cupsmodules,  cupslessons, cupspages, cupssbmain
>WHERE cupsmodules.CourseID = 23
>   AND cupslessons.ModuleID = cupsmodules.ModuleID
>   AND cupspages.LessonID = cupslessons.LessonID
>   AND cupssbmain.PageID = cupspages.PageID
>ORDER BY cupsmodules.Module_Position ASC,
>   cupslessons.Lesson_Position ASC,
>   cupspages.Page_Position ASC
>
>I think that should give you the right result.  So... it is possible
>without using INNER JOIN or LEFT JOIN.  We had a discussion last year
>on NYPHP-MySQL about INNER JOIN versus commas (cartesian join) -- you
>so often see it with commas in tutorials and other people's code.

It has also been argued that WHERE clauses, even very elaborate ones 
like those above, are preferable to joins, since they are (unlike 
joins) absolutely explicit about what is to be matched, and are thus 
less likely to lead to confusion and problems. I rather like that 
argument myself.


Michael Southwell, Vice President for Education
New York PHP
http://www.nyphp.com/training - In-depth PHP Training Courses





More information about the talk mailing list