开发者

PHP MySQL, UNION TABLES

开发者 https://www.devze.com 2023-03-29 23:45 出处:网络
Got a query like this: SELECT * FROM job WHERE status!=2 AND status!=3 UNION SELECT * FROM emp WHERE status!=2 AND status!=3

Got a query like this:

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

It works perfectly, but now can't identify where 开发者_StackOverflowfrom record is coming... Is there any way to identify from which table, the record is coming?


I guess you could try this:

      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

This should add a field named origin to your results, containing a name of your choice to identify the table.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号