如何用一条SQL语句查询3个表中的内容?
2个回答
展开全部
前提是表的结构应该是一样的或者处理成一样的~~~~
表A, aid, aname, atext
表B, bid, bname, btext
表C, cid, cname, ctext
SELECT * FROM (
SELECT aid AS id, aname AS name, atext AS [text] FROM A
UNION
SELECT bid AS id, bname AS name, btext AS [text] FROM B
UNION
SELECT cid AS id, cname AS name, ctext AS [text] FROM C
) Tmp WHERE name LIKE '%key%' OR [text] LIKE '%key%' ORDER BY id DESC
表A, aid, aname, atext
表B, bid, bname, btext
表C, cid, cname, ctext
SELECT * FROM (
SELECT aid AS id, aname AS name, atext AS [text] FROM A
UNION
SELECT bid AS id, bname AS name, btext AS [text] FROM B
UNION
SELECT cid AS id, cname AS name, ctext AS [text] FROM C
) Tmp WHERE name LIKE '%key%' OR [text] LIKE '%key%' ORDER BY id DESC
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询