Your blog a part of our website is wordpress. What i must do in order to the house page from the primary website is to accept newest blog publish excerpt and put it around the primary site having a connect to the content around the blog. I am looking to get the SQL statement to operate correctly and i believe i've the primary pieces, but wish to place it right into a single Choose rather than two Chooses.

The main reason i've two Chooses would be to make certain i recieve the most recent revision from the publish. First i attempt the revision Choose to ascertain if i recieve a row came back - basically do, i am done. If there's no row (no revisions around the publish), make use of the second Choose statement.

SELECT TOP 1 * FROM wp_posts
WHERE post_type = 'revision'
    AND post_parent IN (SELECT [object_id]
                FROM wp_term_relationships
                WHERE term_taxonomy_id = 3)
ORDER BY post_modified DESC

SELECT TOP 1 * FROM wp_posts
WHERE id IN (SELECT [object_id]
            FROM wp_term_relationships
            WHERE term_taxonomy_id = 3)
ORDER BY post_modified DESC

How do i mix both of these Chooses right into a single Choose in order to be confident of always obtaining a row back (i.e. the newest blog publish)

Thanks ahead of time.

SELECT TOP 1 * FROM wp_posts
WHERE (post_type = 'revision'
    AND post_parent IN (SELECT [object_id]
                FROM wp_term_relationships
                WHERE term_taxonomy_id = 3))
OR (id IN (SELECT [object_id]
            FROM wp_term_relationships
            WHERE term_taxonomy_id = 3))
ORDER BY post_modified DESC

Would this meet your needs?

SELECT TOP 1 wp_posts.* 
FROM wp_posts, (SELECT [object_id]
                FROM wp_term_relationships
                WHERE term_taxonomy_id = 3) relations
WHERE 
    (post_type = 'revision' AND post_parent IN relations) OR
    (id IN relations)
ORDER BY post_modified DESC

Or,

SELECT TOP 1 wp_posts.* 
FROM wp_posts, (SELECT [object_id]
                FROM wp_term_relationships
                WHERE term_taxonomy_id = 3) relations
WHERE 
   (post_type = 'revision' AND post_parent IN relations AND id NOT IN relations) OR
   (post_type <> 'revision' AND post_parent NOT IN relations AND id IN relations) 
ORDER BY post_modified DESC

First factor that involves mind is by using UNION and you may take the very first row from the result set:

SELECT TOP 1 * FROM wp_posts
WHERE post_type = 'revision'
    AND post_parent IN (SELECT [object_id]
                FROM wp_term_relationships
                WHERE term_taxonomy_id = 3)
ORDER BY post_modified DESC
UNION
SELECT TOP 1 * FROM wp_posts
WHERE id IN (SELECT [object_id]
            FROM wp_term_relationships
            WHERE term_taxonomy_id = 3)
ORDER BY post_modified DESC

UPDATE

An easy subselect from the previous sql that returns the very first record:

SELECT TOP 1 * FROM (
SELECT TOP 1 * FROM wp_posts
WHERE post_type = 'revision'
    AND post_parent IN (SELECT [object_id]
                FROM wp_term_relationships
                WHERE term_taxonomy_id = 3)
ORDER BY post_modified DESC
UNION
SELECT TOP 1 * FROM wp_posts
WHERE id IN (SELECT [object_id]
            FROM wp_term_relationships
            WHERE term_taxonomy_id = 3)
ORDER BY post_modified DESC)