table1
ID
SUBJECT
CONTENT
table2
ID
SUBJECT
CONTENT
table3
ID
SUBJECT
CONTENT
... 5 more
SUBJECT
すべてのテーブルを検索したい
これどうやってするの?
table1
ID
SUBJECT
CONTENT
table2
ID
SUBJECT
CONTENT
table3
ID
SUBJECT
CONTENT
... 5 more
SUBJECT
すべてのテーブルを検索したい
これどうやってするの?
CREATE VIEW multitable AS
SELECT * FROM table1
UNION SELECT * from table2
UNION SELECT * from table3;
SELECT subject FROM multitable ...
UNION
すべてのテーブルの構文が同じであるため、演算子を使用できます。
SELECT * FROM Table1
UNION Table2
UNION Table3
UNION Table4
UNION Table5
UNION Table6
UNION Table7
UNION Table8
WHERE SUBJECT="Subject"
簡単にするために、8つのテーブルは書き出すのに多すぎません。もっとあれば、動的クエリをお勧めします。
select * from table1 where subject like '%match%' union
select * from table2 where subject like '%match%' union
select * from table3 where subject like '%match%' union
select * from table4 where subject like '%match%' union
select * from table5 where subject like '%match%' union
select * from table6 where subject like '%match%' union
select * from table7 where subject like '%match%' union
select * from table8 where subject like '%match%'