我有以下查询,它在PHP中正常工作:
SELECT g.*
, u.username
FROM games g
JOIN users u
ON g.admin_id = u.id
WHERE g.status < 4
ORDER
BY g.status DESC
, g.start_date DESC;
它返回行并按status desc
然后start_date desc
正确排序。
但是,当我尝试从Node.js运行相同的查询时,它仍会返回所有行,但输入顺序不正确。它似乎按ID排序,这意味着它忽略了上面的order by
条款。为什么这样,我该如何解决?这是代码:
connection.query("
SELECT g.*
, u.username
FROM games g
JOIN users u
ON g.admin_id = u.id
WHERE g.status < 4
ORDER
BY g.status DESC
, g.start_date DESC;
", function(err, rows, fields) {
rows.forEach(function(row) {
//work with each row
});
});
编辑:我正在使用mysql
package连接到MySQL。