There are two possible association conditions for left join, either a.uid=b.uid or a.beUid=b.id.

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

it is correct to use Union to write this

then use the left connection and I will not write, no matter how to write, there will be duplicate data

Jun.28,2021

all I can think of is union


from the example you gave, if the end result takes only the data of the main table in the link and requires no repetition, you should not use the left join.
should use exists, such as:

select *
from a
where exists (select 1 from b where a.uid = b.uid or a.beUid=b.id)
Menu