'FInd a particular Record from more than 2 Tables in sql
I have a 5 to 6 tables in my Database in Sql. I want to find a particular record form those table (eg: welcome dept) I am not aware in which table and which column it is in.
I have 3 tables (Customer_table,Employee_table,Workers_Table) in this I have to search a name (aaa) in all this 3 tables.
How can I write a SQL query?
Solution 1:[1]
You haven't provided much info... so here's my untested guess:
SELECT name
FROM
(
SELECT * FROM Customer_table WHERE name = 'aaa';
UNION ALL
SELECT * FROM Employee_table WHERE name = 'aaa';
UNION ALL
SELECT * FROM Workers_Table WHERE name = 'aaa';
UNION ALL
) tbl
GROUP BY name
HAVING count(*) = 1
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | luisdev |
