如何在下面的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
答案 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