您好!我有两张桌子:
myTable1 - 存储用户名& user_ids
myTable2 - 存储电子邮件& user_ids
我要做的是返回用户名,电子邮件,两者或一行的行,具体取决于采用哪一个(或两者)。我使用以下代码但得到奇怪的结果!
SELECT usr.username, pro.email FROM myTable1 AS usr, myTable2 AS pro WHERE usr.username = 'wookie' OR pro.email = 'wookie@woo.com'
我期待收到两列1行。
列:用户名,行:'wookie'和列电子邮件,行'wookie @ woo.com'
但是我的'wookie'在用户名栏中无数重复,而且电子邮件列只输出了所有用户电子邮件的行(而不是我在声明中指定的那些)。
我做错了吗?
答案 0 :(得分:2)
select
usr.username, pro.email
from
myTable1 as usr
inner join
myTable2 as pro
on usr.user_ids=pro.user_ids
WHERE
(usr.username='wookie' OR pro.email='wookie@woo.com');
答案 1 :(得分:1)
也许你正在寻找一个或类似的东西。
SELECT
usr.username,
pro.email
FROM
myTable1 AS usr
join myTable2 AS pro ON usr.user_ids = pro.user_ids
WHERE
usr.username = 'wookie' OR pro.email = 'wookie@woo.com'
答案 2 :(得分:0)
你必须做一个加入命令:
Select
usr.username,
pro.email
from mytable1 usr
inner join mytable2 pro
on usr.user_id = pro.user_id
Where Statement