i have the following two tables:
Table1
id name
---------
A3 B2
A3 B400
A5 B100
A7 B200
A8 B6
A8 B2
A8 B3
and
Try with UNION DISTINCT like:
SELECT DISTINCT t1.id as ID,
t2.company as Company,
'FOUND' AS status
FROM table1 t1
JOIN table2 t2
ON t1.id = t2.id
group by ID
union distinct
SELECT DISTINCT t2.id as ID,
t2.company as Company,
'FOUND' AS status
FROM table1 t1
JOIN table2 t2
ON t1.name = t2.name
group by ID
union distinct
SELECT t1.name as ID,
t1.name as Company,
'NOT FOUND' AS status
FROM table1 t1
WHERE t1.name NOT IN (SELECT t2.name
FROM table2 t2)
GROUP BY ID