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 構文にエラーがあります。8 行目の「order by id desc」の近くで使用する正しい構文については、MySQL サーバーのバージョンに対応するマニュアルを確認してください。

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 に答える