Mysql 选择使用UNION ALL FALSE

Mysql 选择使用UNION ALL FALSE,mysql,select,union,Mysql,Select,Union,我正在使用UNIONALL对搜索页面进行选择,因此我需要知道结果来自哪个表,为我创建指向正确页面的链接。 有可能吗 例: Cheers Mango只需将表名添加到每个子查询: (SELECT 'video' as tablename, id, title AS tit FROM video WHERE `title` LIKE '%test%') UNION ALL (SELECT 'testimonials' as tablename, id, title AS tit FROM

我正在使用UNIONALL对搜索页面进行选择,因此我需要知道结果来自哪个表,为我创建指向正确页面的链接。 有可能吗

例:


Cheers Mango

只需将表名添加到每个子查询:

(SELECT 'video' as tablename, id, title AS tit 
 FROM video 
 WHERE `title` LIKE '%test%')
 UNION ALL
(SELECT 'testimonials' as tablename, id, title AS tit 
 FROM testimonials 
 WHERE `title` LIKE '%test%' AND _type = 'news')
 UNION ALL
(SELECT 'image_gallery' as tablename, id, title AS tit 
 FROM image_gallery
 WHERE `title` LIKE '%test%' AND id_gallery = '1')

将表名添加到SELECT语句中如何

(SELECT id, title AS tit, 'video' as tname FROM video WHERE `title` LIKE '%test%')
UNION ALL
(SELECT id, title AS tit, 'testimonials' as tname FROM testimonials WHERE `title` LIKE '%test%' AND _type = 'news')
UNION ALL
(SELECT id, title AS tit, 'image_gallery' as tname FROM image_gallery  WHERE `title` LIKE '%test%' AND id_gallery = '1')

谢谢你,瑞克,我不知道这是可能的!
(SELECT id, title AS tit, 'video' as tname FROM video WHERE `title` LIKE '%test%')
UNION ALL
(SELECT id, title AS tit, 'testimonials' as tname FROM testimonials WHERE `title` LIKE '%test%' AND _type = 'news')
UNION ALL
(SELECT id, title AS tit, 'image_gallery' as tname FROM image_gallery  WHERE `title` LIKE '%test%' AND id_gallery = '1')