MySQL Union输出查询

时间:2012-03-11 15:46:23

标签: mysql sql innodb union

如何获取输出或查询行所在的表。 我需要知道行包含哪个表的输出。

sprinf(SELECT id,alias,title,id_category FROM blog_article 
UNION 
SELECT id,alias,title,id_category FROM forum_thread 
WHERE LOWER(title) LIKE '%s%%' LIMIT 5, $key);

1 个答案:

答案 0 :(得分:0)

sprinf(SELECT "blog_article" as tbl,id,alias,title,id_category FROM blog_article 
UNION 
SELECT "forum_thread" as tbl,id,alias,title,id_category FROM forum_thread 
WHERE LOWER(title) LIKE '%s%%' LIMIT 5, $key);

行将有blog_article或forum_thread作为第一个字段“tbl”,您可以从中识别该行来自哪个表