如何结合这两个凭据查询?

时间:2014-11-12 03:01:06

标签: mysql sql

我想将这两个查询放入一个查询中。查询的目的是检查凭证是否与表中的任何一个匹配" user_credentials"或"工人"。我怎么能这样做?

  

SELECT user_name FROM user_credentials WHERE user_name =' $ user_email'   AND password =' $ user_password'

     

SELECT user_name FROM workers WHERE user_name =' $ user_email'   AND password =' $ user_password'

1 个答案:

答案 0 :(得分:1)

试试这个

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_num_rowsmysql_num_rows