MySQL按顺序排序或结果

时间:2016-02-11 15:16:55

标签: mysql

SELECT
    * 
FROM
    users 
where
    email = 'email@example.com'
    or
    address = '123456' 

我如何获得第一个条件的结果email = 'email@example.com'冷杉?

2 个答案:

答案 0 :(得分:3)

是的,您可以使用CASE表达式:

SELECT
    * 
FROM
    users 
where
    email = 'email@example.com'
    or
    address = '123456' 
order by 
    case 
        when email = 'email@example.com' then 1 
        else 2 
    end

答案 1 :(得分:0)

python filename.py