开发者

where query count result > 0

开发者 https://www.devze.com 2022-12-21 07:42 出处:网络
I need to do a query like this: SELECT wposts.ID FROM posts wposts WHERE ( SELECT CO开发者_StackOverflowUNT(ID) FROM surveys WHERE POST_ID = wposts.ID) > 0

I need to do a query like this:

SELECT wposts.ID FROM posts wposts WHERE ( SELECT CO开发者_StackOverflowUNT(ID) FROM surveys WHERE POST_ID = wposts.ID) > 0

but need it to be working ?


Select returns by default a "set", which is not compatible with an integer. You can do something like:

SELECT wposts.ID FROM posts wposts WHERE 0 NOT IN ( SELECT COUNT(ID) FROM surveys WHERE POST_ID = wposts.ID)


The following SQL works fast, if the foreign key surveys.POST_ID is indexed.

SELECT wposts.ID FROM posts wposts
    INNER JOIN surveys ON surveys.POST_ID = wposts.ID
GROUP BY wposts.ID
0

精彩评论

暂无评论...
验证码 换一张
取 消