0

我有两个选择语句

SELECT username, password FROM users WHERE username='$Uname'

SELECT email_address FROM users WHERE email_address='$email'

我可以使用什么语句,以便我立即获得所有结果,即

用户名作为结果 [0],密码作为结果 [1],电子邮件地址作为结果 [2]

为了更好地解释。

我想检查我的数据库中是否已经有用户名的记录,如果有,然后获取密码,然后检查密码是否还有 email_address 的记录,以确保不允许用户拥有重复的用户名或电子邮件地址。

4

4 回答 4

1

我认为你想要一个“或”条件:

SELECT username, password, email_address 
FROM users
WHERE username='$Uname' or email_address='$email'

您可以使用相关子查询检查电子邮件是否存在:

SELECT username, password, email_address
       (select (case when count(*) > 0 then 'SHARED' else 'UNIQUE' end)
        from users u2
        where u.email_address = u2.email_address and
              u.username <> u2.user_name
      ) as SharedOrUnique
FROM users u
WHERE username='$Uname' or email_address='$email'
于 2012-08-14T14:25:38.803 回答
1

联合查询结合了多个选择查询的结果。

SELECT name, price, warranty_available, exclusive_offer
FROM Products
UNION ALL
SELECT name, price, guarantee_available, exclusive_offer
FROM Services;
于 2015-12-15T05:29:36.177 回答
0

I have no idea what you're attempting to do but...

SELECT u1.username, u1.password, u2.email_address 
from users u1, users u2
where u1.username='$UName'
and u2.email_address == '$email'

Given that your second query is just going to return the value you pass in....

SELECT username, password, '$email' as email_address FROM users WHERE username='$Uname'  
于 2012-08-14T14:02:15.603 回答
0

如果您已经知道电子邮件地址(第二个语句变量),那么您为什么希望您的语句再次返回它?

于 2012-08-14T14:00:46.837 回答