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 回答