仅显示未访问的链接

Every time someone clicks a link on my website I log the id of the link and the username of the person who clicked it into a table called out_log. I have another table called links.

$query = "SELECT *
FROM links 
ORDER BY id DESC
LIMIT 0, 10";

I'm looking for a way to only show those id's that haven't been clicked by the user.

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

You can use...

SELECT id FROM user_tab where user_id NOT IN (SELECT id FROM user_log)