-1

我正在尝试通过 mysqli 查询获取数据。查询看起来像:

SELECT * FROM pxldr_drawings
             ORDER BY RAND()
             WHERE id NOT IN (1,3,4,2)
             LIMIT 1

但我收到以下错误消息

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id NOT IN (1,3,4,2) LIMIT 1' at line 3

我也试过 NOT IN ('1','3','4','2')and NOT IN(1,3,4,2),但都没有成功。

谢谢,LB

4

2 回答 2

3

WHERE子句必须在ORDER BY子句之前。

试试这个

      SELECT * FROM pxldr_drawings
          WHERE id NOT IN (1,3,4,2)
          ORDER BY RAND()
          LIMIT 1
于 2013-08-17T15:32:41.323 回答
1

子句的顺序很重要,order by应该在后面where

SELECT * FROM pxldr_drawings
             WHERE id NOT IN (1,3,4,2)
             ORDER BY RAND()
             LIMIT 1

关于需要放置不同子句的正确语法,请参阅“选择语法”文档。

于 2013-08-17T15:32:35.897 回答