我想结合这两个查询。
SELECT * FROM table1 WHERE status='pending' and adr='' order by id desc limit 0,1;
SELECT * FROM table1 where status='pending' and adr='new' ORDER BY RAND() LIMIT 1
答案 0 :(得分:0)
您可以使用UNION ALL集合运算符来连接两个查询的结果
( SELECT * FROM table1 WHERE status='pending' AND adr='' ORDER BY id DESC LIMIT 1 )
UNION ALL
( SELECT * FROM table1 WHERE status='pending' AND adr='new' ORDER BY RAND() LIMIT 1 )
参考:UNION ALL https://dev.mysql.com/doc/refman/5.5/en/union.html