2012-12-20 53 views
2

這是我的查詢:正被選擇MySQL的:選擇一排,其中一列等於ID

SELECT ID FROM wp_posts 
WHERE post_type = 'vreb_property' 
AND post_status = 'publish' 
ORDER BY post_modified DESC 

在這種情況下,我需要修改我的查詢,包括WHERE post_parent = ID ...這樣的ID,我需要使用。

SELECT ID FROM wp_posts WHERE post_type = 'vreb_property' ... and also select records where 'post_parent' = ID

因爲有是post_type「附件」,我需要抓住的記錄。

爲了澄清這個請求的有效性,我可以多看幾眼嗎?謝謝。

+1

您在查詢中傳遞的已知ID? – 2012-12-20 00:38:55

+0

呃,比這更復雜一點......我編輯了上面的問答。 – dcolumbus

回答

0

您是否在尋找OR

SELECT ID FROM wp_posts 
WHERE (post_type = 'vreb_property' 
     AND post_status = 'publish') 
    OR (post_type = 'attachment' 
     AND post_parent = ID) 
ORDER BY post_modified DESC 

使用括號可以使其適應您的具體需求,因爲這不完全清楚。

+0

不幸的是,這隻會返回一些結果...條件是'post_parent = ID',但需要返回的不僅是匹配'post_type ='vreb_property'和post_status ='publish''的行,還包括那些匹配'post_type ='附件'和post_parent = ID' – dcolumbus

+0

@dcolumbus這只是對條件的小改動,請參閱我的編輯。訣竅在括號中。 – jeroen

+0

不幸的是,這仍然只能返回10個結果...所以爲了澄清一下,我需要兩種情況來完成結果。 'post_type ='vreb_property'AND post_status ='publish''以及'post_type ='附件'AND post_parent = ID' – dcolumbus

-1

我同意jeroen的SQL,訣竅在括號中。

相關問題