如果它有 10 个表,那么大概您可以提前检查它们并知道您要查看哪些列。然后挑战是将所有这些组合到一个查询中。你可以用一堆 UNION 来做,像这样:
select [Emp name] as Name, [dob] as DateOfBirth, [work email] as Email, [national id] as ID, 'Table1' as TableName
from Table1
UNION
select [Full Nm] as Name, [date of birth] as DateOfBirth, [Wrk Email] as Email, [NID] as ID, 'Table2' as TableName
from Table2
UNION
select [Full Name] as Name, [birth date] as DateOfBirth, [Work Em] as Email, [NatID] as ID, 'Table3' as TableName
from Table3
UNION
--etc etc
注意我们如何添加一个 TableName 列来告诉我们每个项目来自哪个表。
要查询整个数据集,您需要将其声明为视图或类似的东西,或者将其嵌套在另一个 SELECT 中,如下所示:
select Name, DateOfBirth, Email, ID, TableName
from (
select [Emp name] as Name, [dob] as DateOfBirth, [work email] as Email, [national id] as ID, 'Table1' as TableName
from Table1
UNION
select [Full Nm] as Name, [date of birth] as DateOfBirth, [Wrk Email] as Email, [NID] as ID, 'Table2' as TableName
from Table2
UNION
select [Full Name] as Name, [birth date] as DateOfBirth, [Work Em] as Email, [NatID] as ID, 'Table3' as TableName
from Table3
UNION
--etc etc
) giveitaname
WHERE [Name] = 'Joe Bloggs' and [DateOfBirth] = '01/Feb/1999'