好的,所以我有一个名为 posts 的表,我试图删除重复项,条件是如果 post_id 之一等于 post_dat_id 并且只有在 post_data_id == post_id 的 post_type 为 2 时才删除它。
帖子结构
post_id || post_data_id || post_type || post_user_id
==================================
1 || NULL || 0 || 10210
2 || 1 || 2 || 201020 <-- it shouldn't show this one because it meets the condition that post_type == 2 && the post_data_id is equal to one of the post_id. EDIT: also notice how this id = 2 but the post_data_id = 1. It is impossible for a row ot have the same post_id & post_data_id
2 || 1 || 0 || 202020
3 || 6 || 2 || 202020
我的mysql:
SELECT p.*
FROM posts p
LEFT JOIN following f ON f.user_id =1
AND p.post_user_id = f.follower_id
WHERE post_user_id =1
OR f.user_id IS NOT NULL
ORDER BY `p`.`post_time` DESC
LIMIT 0 , 10
编辑:我不想删除代码,如果满足我选择的条件,我想做的就是不显示该结果。另外我已经在使用左连接,因为我的 sql 代码需要检查下表来获取用户 ID
编辑 2:我还将 post_data 更改为 post_data_id 所以它现在是一个纯 int