mySQL全文联合搜索返回表名

时间:2011-11-11 20:35:50

标签: mysql

如何在下面的mysql全文联合搜索中返回表名?

(SELECT title,content,date 
FROM table1 
WHERE (MATCH 
(title,content) 
AGAINST 
('+$boolean' IN BOOLEAN MODE))
) UNION (
SELECT title,content,date 
FROM table2 
WHERE (MATCH 
(title,content) 
AGAINST 
('+$boolean' IN BOOLEAN MODE)))  
Order By date DESC 
LIMIT 0,10

2 个答案:

答案 0 :(得分:0)

(SELECT 'table1' as table_name, title,content,date 
FROM table1 
WHERE (MATCH 
(title,content) 
AGAINST 
('+$boolean' IN BOOLEAN MODE))
) UNION (
SELECT 'table2' as table_name, title,content,date 
FROM table2 
WHERE (MATCH 
(title,content) 
AGAINST 
('+$boolean' IN BOOLEAN MODE)))  
Order By date DESC 
LIMIT 0,10

答案 1 :(得分:0)

(SELECT title,content,date, 'Table1' as TableName
FROM table1 
WHERE (MATCH 
(title,content) 
AGAINST 
('+$boolean' IN BOOLEAN MODE))
) UNION (
SELECT title,content,date, 'Table2' as TableName
FROM table2 
WHERE (MATCH 
(title,content) 
AGAINST 
('+$boolean' IN BOOLEAN MODE)))  
Order By date DESC 
LIMIT 0,10