查询:
SELECT id, username,
(SELECT username
FROM users
WHERE email = '{$email}'
AND activate = 0 ) AS inactive
FROM users
WHERE email = '{$email}'
AND password = '{$password}'
AND activate = 1
字段电子邮件为UNIQUE
,因此电子邮件中没有重复。
如果组合username
存在,我想输出id
和email,password,activate=1
如果组合username
,我想输出inactive
email,activate=0
存在。
SELECT id,
(SELECT username
FROM users
WHERE email = '{$email}'
AND activate = 0
) AS inactive,
(SELECT username
FROM users
WHERE email = '{$email}'
AND activate = 1
AND password = '{$password}'
) AS active
FROM users
WHERE email = '{$email}'
答案 0 :(得分:1)
尝试以下
select id,
case activate
when 0 then 'inactive'
when 1 then username
end as username
from users
WHERE email = '{$email}'
AND (activate = 0 or password = '{$password}')
case语句用于在列或表达式的多个选项之间进行选择