Mysql 如何组合这两个凭据查询?
我想把这两个查询变成一个查询。查询的目的是检查凭据是否与表“user\u credentials”或“workers”中的任何一个匹配。我怎样才能做到 从user\u凭据中选择user\u name,其中user\u name=“$user\u email” 密码=“$user\u password” 从工作区中选择用户名,其中用户名=“$user\u email” 密码=“$user\u password” 试试这个Mysql 如何组合这两个凭据查询?,mysql,sql,Mysql,Sql,我想把这两个查询变成一个查询。查询的目的是检查凭据是否与表“user\u credentials”或“workers”中的任何一个匹配。我怎样才能做到 从user\u凭据中选择user\u name,其中user\u name=“$user\u email” 密码=“$user\u password” 从工作区中选择用户名,其中用户名=“$user\u email” 密码=“$user\u password” 试试这个 SELECT user_name FROM user_credentials
SELECT user_name FROM user_credentials WHERE user_name = '$user_email' AND password = '$user_password'
union
SELECT user_name FROM workers WHERE user_name = '$user_email' AND password = '$user_password'
然后检查
mysqli\u num\u rows
或mysql\u num\u rows
您是否考虑过union all
?是的,但它们有不同的属性/列。您正在从每个列中选择username
,而不是从其他列中选择。这对于联合所有
来说应该是可以的。我认为它必须是唯一的,应该是联合
而不是联合所有
?