1

我正在尝试在此语句中注入 sql union 语句。

select id, email, `password` from users
where id = 1 union select 1,2,3;
order by users.id

但它返回一个错误:

[Err] 1064 - 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的“order by users.id”附近使用正确的语法

我怎样才能让这个声明起作用?

4

1 回答 1

7

去掉;前面的ORDER BY子句

select id, email, password 
from users where id = 1 
union 
select 1,2,3
order by id

更新 1

SELECT  id, email, password
FROM
    (
        SELECT  id, email, password, 1 AS orders
        FROM    users 
        WHERE   id = 1 
        UNION 
        SELECT  1,2,3,2
    ) s
ORDER BY orders, id
于 2013-01-02T09:49:17.037 回答