我有一个数据库与多个表,即table1,table2,table3具有相同的字段。不知何故,我无法将这些表合并成一个。Sql搜索多个表
有没有什么办法可以按照相同的标准一个接一个地查询它们,例如,如果在第一个表中找到记录,则返回找到的记录,否则在第二个表中搜索依此类推。 像:
Select * from table1 where cloumnX = 'xyz'
if found return the rocord
else
Select * from table2 where cloumnX = 'xyz'
...
Select * from lastTable where cloumnX = 'xyz'
如果你有这样的枚举表,你应该考虑修复你的模式设计。 – GurV
你可以使用'UNION' – Stephen
你能描述你为什么要这样做吗?我有一种感觉,有一种比你想象的更好的方式。 – user3685285