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)
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b30fd4-2bd87.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b30fd4-2bd87.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?