我有这样的查询:
SELECT * FROM job WHERE status!=2 AND status!=3
UNION SELECT * FROM emp WHERE status!=2 AND status!=3
ORDER BY (id/popularity) DESC LIMIT {$from},$vpc
它运作完美,但现在我无法确定记录的来源...... 有没有办法确定从哪个表开始记录?
答案 0 :(得分:8)
我想你可以试试这个:
SELECT *, 'job' as origin
FROM job
WHERE status!=2
AND status!=3
UNION SELECT *, 'emp' as origin
FROM emp
WHERE status!=2
AND status!=3
ORDER BY (id/popularity) DESC
LIMIT {$from},$vpc
这应该在结果中添加一个名为origin的字段,其中包含您选择的名称以标识该表。