每次有人点击我网站上的链接时,我都会将链接的 ID 和点击者的用户名记录到名为 out_log 的表中。我有另一个名为链接的表。
$query = "SELECT *
FROM links
ORDER BY id DESC
LIMIT 0, 10";
我正在寻找一种仅显示用户未点击的ID的方法。
Something like this query should work.
SELECT *
FROM links
WHERE id NOT IN (
SELECT link_id
FROM out_log
WHERE user_id = <user_id>
)
ORDER BY id DESC
LIMIT 0, 10
您可以使用...
SELECT id FROM user_tab where user_id NOT IN (SELECT id FROM user_log)