2012-12-20 52 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,诀窍在括号中。

相关问题