Answer the question
In order to leave comments, you need to log in
How to get values from several MySQL tables so that as a result it is possible to determine from which table which values were extracted?
How to get values from 3 MySQL tables, so that as a result you can determine from which table which values \u200b\u200bare extracted?
This option is not suitable:
SELECT id
FROM table1
WHERE name= 'Tom'
UNION
SELECT id
FROM table2
WHERE name= 'Tom'
UNION
SELECT id
FROM table3
WHERE name= 'Tom'
Answer the question
In order to leave comments, you need to log in
SELECT 'table1' as tabl, id
FROM table1
WHERE name= 'Tom'
UNION
SELECT 'table2' as tabl, id
FROM table2
WHERE name= 'Tom'
UNION
SELECT 'table3' as tabl, id
FROM table3
WHERE name= 'Tom'
the question is not clear at all, but I'll take a chance:
group_concat(distinct a.id )AS table1_id, ifnull(group_concat(distinct b.id), '-') AS table2_id, group_concat( distinct c.id) AS table3_id
from table1 a
left join table2 b on a.name = b.name
left join table3 c on c.name = b.name or a.name=c.name
where a.name='tom' or b.name ='tom' or c.name ='tom'
right?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question