我有一個數據庫與多個表,即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