这个SQL查询出了什么问题:
select a.*
from samples_order a
inner join
(
select distinct customeremail, min(id) as id
from samples_order group by customeremail
) as b
on a.customeremail = b.customeremail
and a.id = b.id where order_site="blindsuk"
and order_status = "logged" limit 50, 0
order by id desc
返回错误: 您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以便在第8行的'order by id desc'附近使用正确的语法
select a.*
from samples_order a
inner join (
select distinct customeremail, min(id) as id
from samples_order
group by customeremail
) as b on a.customeremail = b.customeremail and a.id = b.id
where order_site="blindsuk"
and order_status = "logged"
limit 50, 0
order by id desc
答案 0 :(得分:3)
ORDER BY
子句应该在LIMIT
所以,
SELECT a.*
FROM samples_order a
INNER JOIN (
SELECT DISTINCT customeremail
, min(id) AS id
FROM samples_order
GROUP BY customeremail
) AS b
ON a.customeremail = b.customeremail
AND a.id = b.id
WHERE order_site = "blindsuk"
AND order_status = "logged"
ORDER BY id DESC -- ORDER BY before LIMIT
LIMIT 50, 0