select t.*
from talk t
where t.user_id = 2
Union
select t.*
from talk t, user_contact c
where c.user_id = 2 and c.contact_type = 1 and c.be_user_id = t.user_id
you can write it this way, but you don"t want to write it this way. You want to use an inner connection or a left connection
.there is a situation where the user has no data in the user_contact table, which means he is not paying attention to anyone
user_id = 1 is the user"s id, that is, my id
select 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)
I don"t understand what"s wrong. Why is there duplicate data
?I write the query like this and there is duplicate data
user_contact is the user relation table
talk is the post table
posts table talk has the user_id of the user who posted the post
then the user relations table user_contact stores that user_id,be_user_id is the followed user"s id,contact_typ_type is the user relationship type, 1 is the follow type
ask for advice. I don"t know how to write
.