I'm using WordPress. I want to select a group of id's in one table, and use those id's to select a bunch of posts in another table, and only retrieve the most recent post.
So, theoretically, I want to do this:
$article_ids_query = mysql_query("SELECT
term_taxonomy_id='" . $term_taxonomy_id . "'"); //this will retrieve a bunch of
$articles = mysql_query("SELECT
ID='" . $article_ids_query . "' LIMIT 1 ORDER BY
The obvious problem is that the $article_ids_query is going to be a result set.
How could I do it so that I use the query in $article_ids_query to be part of the $articles query.
This is what I could come up with using a "UNION", but I've never used UNION before:
term_taxonomy_id='" . $term_taxonomy_id . "') UNION (SELECT
post_type='post') LIMIT 1 ORDER BY
Of course, I appreciate any and all help. Josh
FROM wp_term_relationships AS r
JOIN ( SELECT id
, MIN(post_date) AS first_post
BY id ) AS m
ON m.id = r.object_id
JOIN wp_posts AS p
ON p.id = m.id
AND p.post_date = m.first_post
WHERE r.term_taxonomy_id = " . $term_taxonomy_id
Josh, maybe use a plugin (http://wordpress.org/extend/plugins/recent-posts-plugin/)? I thought I had another plugin installed but guess not.
WOW. I don't know how many yrs experience you have doing this stuff, but that query worked beautifully and I am impressed at it. Thank you.