帮助转换SQL嵌套子查询以加入MySQL 4.0兼容性的查询
-
08-10-2019 - |
题
我有一个嵌套的SQL查询:
SELECT DISTINCT(topic_id)
FROM bb_posts
WHERE topic_id NOT IN (
SELECT topic_id FROM bb_posts
WHERE poster_id = $user_id AND post_status = 0 )
ORDER BY post_time DESC
我的Web服务器运行MySQL 4.0,不允许嵌套查询。一些SQL Guru可以使用Join Lingo建议相同的查询吗?我尝试并尝试了...但是我无法弄清楚。感到愚蠢。
解决方案
假设主题_ID不是无效的,您可以做:
SELECT DISTINCT(T1.topic_id)
FROM bb_posts As T1
Left Join bb_posts As T2
On T2.topic_id = T1.topic_id
And T2.poster_id = $user_id
And T2.post_status = 0
Where T2.topic_id Is Null
ORDER BY T1.post_time DESC
其他提示
我不太确定您的要求是什么,但是通过查看您的查询,我认为这应该足够了。
SELECT DISTINCT(topic_id)
FROM bb_posts
WHERE poster_id <> $user_id OR post_status <> 0
ORDER BY post_time DESC
不隶属于 StackOverflow