[thelist] MySQL query with two left joins
Gary McPherson
genyus at ingenyus.net
Wed Jul 2 08:55:21 CDT 2003
> > I'm not sure if MySQL supports the use of a sub-select in
> the SELECT
> > clause, but if it does, can you give me an idea of how to do this?
>
> SELECT c.CategoryID,
> c.Title,
> (SELECT Count(*)
> FROM jn_DocumentCategories dc
> WHERE dc.CategoryID = c.CategoryID) AS documents_in_category
> FROM Categories c WHERE 2 IN (c.ParentCategoryID, c.CategoryID)
Subqueries like this are only supported in MySQL 4.1+. If an older
version is installed, you either have to upgrade or figure out a
workaround (which I believe I may be able to do with a little
headscratching).
Gary
More information about the thelist
mailing list