gpt4 book ai didi

mysql - 将两个 mysql 查询与两个不同的 order by 语句组合起来

转载 作者:行者123 更新时间:2023-11-29 22:22:39 25 4
gpt4 key购买 nike

我想合并这两个查询。

   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

最佳答案

您可以使用 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

关于mysql - 将两个 mysql 查询与两个不同的 order by 语句组合起来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30566469/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com