I'm currently attempting to write my first WordPress plugin, which is the first time I've really used PHP and MySQL, other than to do some basic cleaning up of other people's stuff.
I'm currently trying to write a query that'll bring back the titles of all the posts, plus the ID of the highest-IDed comment for that post (or null, if there's none). I've got:
SQL code: SELECT kj_posts.ID, kj_posts.post_date, max( kj_comments.comment_ID ) , kj_posts.post_title
FROM kj_posts
LEFT OUTER JOIN kj_comments ON kj_comments.comment_post_id = kj_posts.ID
WHERE 1=1
GROUP BY kj_comments.comment_post_id
It almost works - for posts that have comments, it behaves as I want it to, but it only returns one of the posts that don't have any comments. Does MySQL have any clevers to let me do what I want, or will I have to dump the OUTER JOIN stuff and just bung a subquery into the SELECT clause?
Kenny
The Wisdom of Amazon customer reviews:
Kurt Vonnegut: Slaughterhouse 5
My main problem, apart from the uber-randomness, is that the events in the book didn't actually happen, and the main character didn't actually go through the war, because he didn't exist. I'm a freshman in high school, and I was relieved when my English G/T (Lyceum) teacher confirmed my suspiciouns that Kurt Vonnegut was, in fact, high. |