gpt4 book ai didi

jquery - 带有 UNION order by 问题的 sql 查询

转载 作者:行者123 更新时间:2023-11-29 11:42:40 24 4
gpt4 key购买 nike

我想进行一个 Order By 查询,但我不知道为什么它不起作用,这是我的查询,我不知道在哪里放置 order by,我对每个选择进行了测试,但不起作用,测试将其放在最后一个查询没有变化,你能帮我吗?我想通过 a.id 订购

$data = null;
$sth = Model::connect()->prepare(" SELECT a.*, b.ciudad, d.catgoria, d.categorie, e.mark AS marka , c.fuel FROM table1 a,
fuel c ,ciudad b, table2 d , coches e WHERE
a.ciudad = b.id_vil AND a.mark = e.id AND a.fuel = c.id AND d.id = a.table3 AND a.status = 1

UNION
SELECT a.*, b.ciudad, d.catgoria, d.categorie, e.mark AS marka , c.fuel FROM table1 a,
fuel c ,ciudad b, table2 d , liste_vehicules_marchandises e WHERE
a.ciudad = b.id_vil AND a.mark = e.id AND a.fuel = c.id AND d.id = a.table3 AND a.status = 1
UNION
SELECT a.*, b.ciudad, d.catgoria, d.categorie, e.mark AS marka , c.fuel FROM table1 a,
fuel c ,ciudad b, table2 d , liste_vehicules_agricultures e WHERE
a.ciudad = b.id_vil AND a.mark = e.id AND a.fuel = c.id AND d.id = a.table3 AND a.status = 1
UNION
SELECT a.*, b.ciudad, d.catgoria, d.categorie, e.mark AS marka , c.fuel FROM table1 a,
fuel c ,ciudad b, table2 d , bc_vehicule e WHERE
a.ciudad = b.id_vil AND a.mark = e.id AND a.fuel = c.id AND d.id = a.table3 AND a.status = 1


");
$sth->execute();
$data = $sth->fetchAll();
return $data;

最佳答案

您可以添加:

order by id

作为查询中的最后一行。

此外,我建议您使用 UNION ALL 而不是 UNION,除非您特别想承担删除重复项的开销。

关于jquery - 带有 UNION order by 问题的 sql 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35510862/

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