select t.*from talk twhere t.user_id = 2Unionselect t.*from talk t, user_contact cwhere c.user_id = 2 and c.contact_type = 1 and c.be_user_id = t.user_id這么寫可以但是不想這么寫 ,想用 內連接或者左連接存在一種情況就是這個user在user_contact 表里面沒數據,代表他沒關注任何人user_id = 1 是用戶的id,也就是我的idselect t.*
from talk t left join user_contact c on c.user_id = t.user_id
where t.user_id = 1 or (c.user_id = 1 and c.be_user_id = t.user_id and c.contact_type = 1)搞不明白哪里有錯啊,為啥就會有重復數據呢我這樣寫查詢出來有重復數據user_contact是用戶關系表talk 是帖子表帖子表talk有存發布帖子的用戶的user_id然后用戶關系表user_contact 存了 user_id,be_user_id是被關注的用戶的id,contact_typ_type是用戶關系類型,1為關注類型求教,不知道該怎么寫了
1 回答

Helenr
TA貢獻1780條經驗 獲得超4個贊
select * from talk where user_id=1 or user_id in (select be_user_id from user_contact where user_id=1 and contact_type = 1)
添加回答
舉報
0/150
提交
取消