0

I have 3 tables that I want to be able to combine in a view:

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

So basically, I want to map the contents of each of these tables to my single result view which I am then able to query which will be like:

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

So I can do:

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

Is this achievable and how do I go about it?

4

1 に答える 1

2

Try this

 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'

This will club all the records in your view

于 2013-02-25T17:21:45.943 に答える