[英]Check data from multiple tables?
I am trying to check data from different tables, here is the breakdown of what I am trying. 我正在尝试检查来自不同表的数据,这是我正在尝试的分解。 Say I have two tables C & D. Both tables have the columns username and password. 假设我有两个表C和D。两个表都有用户名和密码列。 I am trying to query both of them to see if at least one of them contain the correct username or password. 我试图查询它们两个,以查看它们中至少有一个包含正确的用户名或密码。 Here is the code I came up with but it doesn't seem to be returning correct results. 这是我想出的代码,但似乎未返回正确的结果。
SELECT USERNAME
, PASSWORD
FROM D
, C
WHERE D.USERNAME ="HI"
OR C.USERNAME="HI"
and D.PASSWORD="PASS"
OR C.PASSWORD="PASS";
This just returns a blank result list when I know that Table D will contain the username Hi and password pass. 当我知道表D将包含用户名Hi和密码传递时,这只会返回空白结果列表。 Can you guys see anything wrong with my query? 你们看到我的查询有什么问题吗?
You should be writing this as a UNION
, not a JOIN
: 您应该将其编写为UNION
而不是JOIN
:
SELECT USERNAME,PASSWORD
FROM D
WHERE D.USERNAME ="HI" AND D.PASSWORD="PASS"
UNION
SELECT USERNAME,PASSWORD
FROM C
WHERE C.USERNAME ="HI" AND C.PASSWORD="PASS"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.