1
table1
 ID
 SUBJECT
 CONTENT

table2
 ID
 SUBJECT
 CONTENT

table3
 ID
 SUBJECT
 CONTENT

... 5 more

SUBJECTすべてのテーブルを検索したい

これどうやってするの?

4

3 に答える 3

2
CREATE VIEW multitable AS
SELECT * FROM table1
UNION SELECT * from table2
UNION SELECT * from table3;

SELECT subject FROM multitable ...
于 2011-10-06T18:26:01.940 に答える
0

UNIONすべてのテーブルの構文が同じであるため、演算子を使用できます。

SELECT * FROM Table1
UNION Table2
UNION Table3
UNION Table4
UNION Table5
UNION Table6
UNION Table7
UNION Table8
WHERE SUBJECT="Subject"

簡単にするために、8つのテーブルは書き出すのに多すぎません。もっとあれば、動的クエリをお勧めします。

于 2011-10-06T18:27:44.780 に答える
0
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%'
于 2011-10-06T18:24:18.527 に答える