[thelist] mysql: max in joins?

Beam sbeam at syxyz.net
Tue Mar 4 15:40:01 CST 2003


> Here's the query and the error. I'm not sure if I've even pin-pointed the
> right problem in the query.
>
> mysql> select meta_articles.id, meta_articles.subject,
> meta_articles.created,
> -> meta_comments.max(created) as updated,
> meta_comments.name as who
> -> from meta_comments
>     -> left join meta_articles on meta_comments.articles_id =
> meta_articles.id -> where meta_articles.cats_id = 1 group by id order by
> created ASC; ERROR 1064: You have an error in your SQL syntax near
> '(created) as updated, meta_comments.name as who from meta_comments
> left join met' at line 2
>

how about "max(meta_comments.created)"?

also you might get a complaint about "id is ambiguous in GROUP BY clause" or
something, so use "GROUP BY meta_articles.id"



More information about the thelist mailing list