SELECT *
FROM domains
WHERE domains_id IN
(
SELECT domains_subscriptions_domain
FROM domains_subscriptions
WHERE domains_subscriptions_selmgec='$_SESSION[selmgec]'
)
AND domains_id NOT IN
(
SELECT domains_block_domain
FROM domains_block
WHERE domains_block_selmgec='$_SESSION[selmgec]'
AND domains_block_member='$_SESSION[member]'
)
ORDER BY RAND()
我想取域中的所有域,这些域也在域订阅中,但是它们不在域块中。这对上面的查询很有用。但我想补充一下
AND domains_id NOT IN
(
SELECT domains_hits_domain
FROM domains_hits
WHERE domains_hits_selmgec='$_SESSION[selmgec]'
AND domains_hits_member='$_SESSION[member]'
)
这对查询来说,所以它也过滤掉了域hits表中的域,但它目前给了我所有的域,因为我推测它是说它只过滤掉域hits表和域hits表中的域,但我希望它是!
非常感谢您的帮助
最佳答案
试试这个:
SELECT *
FROM domains
WHERE domains_id IN
(
SELECT domains_subscriptions_domain
FROM domains_subscriptions
WHERE domains_subscriptions_selmgec='$_SESSION[selmgec]'
)
AND domains_id NOT IN
(
SELECT domains_block_domain
FROM domains_block
WHERE domains_block_selmgec='$_SESSION[selmgec]'
AND domains_block_member='$_SESSION[member]'
UNION ALL
SELECT domains_hits_domain
FROM domains_hits
WHERE domains_hits_selmgec='$_SESSION[selmgec]'
AND domains_hits_member='$_SESSION[member]'
)
ORDER BY RAND()
或
SELECT *
FROM domains
WHERE domains_id IN
(
SELECT domains_subscriptions_domain
FROM domains_subscriptions
WHERE domains_subscriptions_selmgec='$_SESSION[selmgec]'
)
AND NOT (
domains_id IN
(
SELECT domains_block_domain
FROM domains_block
WHERE domains_block_selmgec='$_SESSION[selmgec]'
AND domains_block_member='$_SESSION[member]'
)
OR
domains_id IN
(
SELECT domains_hits_domain
FROM domains_hits
WHERE domains_hits_selmgec='$_SESSION[selmgec]'
AND domains_hits_member='$_SESSION[member]'
)
)
ORDER BY RAND()
关于mysql - sql查询,其中域在预订中,但不在阻止或点击中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14423629/