简体   繁体   中英

MySQL: Selecting a row where a column equals the ID

This is my query:

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

In this scenario, I need to modify my query to include WHERE post_parent = ID ... so the ID that is being selected, I need to use.

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

Because there are records that are of post_type "attachment" that I need to grab.

Could I get a few eyes just to clarify the validity of this request? Thanks.

Are you looking for 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

Using the brackets you can adapt it to your specific needs as that is not completely clear.

我同意jeroen的sql,技巧在括号中。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM