时过滤掉数据。
你好,我正试图根据两列比较两个表。我想看看表中哪些用户名匹配,哪些电子邮件地址不匹配。
这是我尝试的:
select * from ecy t1, users t2 where t1.username = t2.username and t1.email <> t2.email
当我运行这个时,我得到了ecy表中的所有用户,即使他们的电子邮件是相等的。
谢谢。
我不会做两个表的笛卡尔积,并尝试用旧的Ansi方法过滤它。
SELECT u.username, u.email
FROM users u
JOIN ecy e on e.email <> u.email AND u.username = e.username
您也可以尝试使用连接
的子查询选择来执行此操作SELECT username, email
FROM users u
JOIN( SELECT username, email FROM ecy) t on t.username = u.username and t.email <> u.email
演示您希望使用JOIN语法将表连接在一起,而不是进行笛卡尔积。JOIN语法还允许您在连接
你可以试试这个,我没有使用<>在mysql之前。
select * from ecy t1, users t2 where t1.username = t2.username and not t1.email = t2.email