0

我有 3 个表希望能够在视图中组合:

tblContent:
strTitle        | txtContent
content 1 title | content 1 content
content 2 title | content 2 content
content 3 title | content 3 content 

tblNews
news_title      | news_content
news 1 title    | news 1 content
news 2 title    | news 2 content

tblTradeMembers
company_title   | company_content
trade 1 title   | trade 1 content
trade 2 title   | trade 2 content
trade 3 title   | trade 3 content
trade 4 title   | trade 4 content

所以基本上,我想将这些表中的每一个的内容映射到我的单个结果视图,然后我可以查询如下:

title           | content             | from
content 1 title | content 1 content   | tblContent
content 2 title | content 2 content   | tblContent
content 3 title | content 3 content   | tblContent
news 1 title    | news 1 content      | tblNews
news 2 title    | news 2 content      | tblNews
trade 1 title   | trade 1 content     | tblTradeMembers
trade 2 title   | trade 2 content     | tblTradeMembers
trade 3 title   | trade 3 content     | tblTradeMembers
trade 4 title   | trade 4 content     | tblTradeMembers

所以我可以这样做:

select * from custom_view WHERE content LIKE "%3%"

这是可以实现的,我该怎么做?

4

1 回答 1

2

尝试这个

 SELECT strTitle AS 'TITLE', txtContent AS 'Content', 'tblContent' AS 'From'
 UNION     
 SELECT news_title AS 'TITLE', news_content AS 'Content', 'tblNews' AS 'From'
 UNION
 SELECT company_title AS 'TITLE', company_content AS 'Content', 'tblTradeMembers' AS 'From'

这将包含您视图中的所有记录

于 2013-02-25T17:21:45.943 回答