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這么寫可以但是不想這么寫 ,想用 內(nèi)連接或者左連接存在一種情況就是這個(gè)user在user_contact 表里面沒數(shù)據(jù),代表他沒關(guān)注任何人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)搞不明白哪里有錯(cuò)啊,為啥就會(huì)有重復(fù)數(shù)據(jù)呢我這樣寫查詢出來有重復(fù)數(shù)據(jù)user_contact是用戶關(guān)系表talk 是帖子表帖子表talk有存發(fā)布帖子的用戶的user_id然后用戶關(guān)系表user_contact 存了 user_id,be_user_id是被關(guān)注的用戶的id,contact_typ_type是用戶關(guān)系類型,1為關(guān)注類型求教,不知道該怎么寫了
我要用sql查詢出來,我所發(fā)布的帖子和我關(guān)注的用戶發(fā)布的帖子,這個(gè)sql該怎么寫?。?/h1>
繁星點(diǎn)點(diǎn)滴滴
2018-10-24 08:06:34
繁星點(diǎn)點(diǎn)滴滴
2018-10-24 08:06:34