0

这个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
4

1 回答 1

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 
于 2012-11-27T09:41:25.287 回答