gpt4 book ai didi

php - 如何找到2个表之间的mysql差异

转载 作者:行者123 更新时间:2023-11-30 23:29:10 25 4
gpt4 key购买 nike

Pictures 和 Seen_pictures,将 Pictures 表中的图片显示给用户,然后将该图片(它在表中的 ID)移动到 Seen_Pictures,并向用户显示 Pictures 表中的新图片。我需要一个 mysql 方案来输出 Pictures 和 Seen_pictures 表之间的差异,这样我就知道用户没有看到哪些图片,并且可以输出它们。

到目前为止我有这个,但它只适用于 1 个用户,我需要它来说明许多不同的用户:

$result = mysqli_query(
$link,

"SELECT o_Pics.Pic.PicID
FROM o_Pics.Pic
LEFT JOIN o_SeenPics.Seen ON o_Pics.Pic.PicID=o_SeenPics.Seen.PicID
WHERE NOT o_Pics.Pic.ID='".$ID."' AND o_SeenPics.Seen.PicID IS NULL"
);

最佳答案

怎么样

SELECT p.p_id FROM Picture p WHERE p.p_id NOT IN 
(SELECT s.p_id FROM Seen_Picture s WHERE s.u_id = "$user_id")

Picture
p_id(Primary Key) picture

Seen_Picture
id(Primary Key) u_id p_id

关于php - 如何找到2个表之间的mysql差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11618826/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com