7,388
社区成员
发帖
与我相关
我的任务
分享
CREATE TABLE t1 (user_id1 int, username varchar(10),DEAL_DATE DATE )
CREATE TABLE t2 (user_id2 int, usercomments varchar(10))
INSERT INTO t1 values(1,'Lily', '2018-01-01')
INSERT INTO t1 values(2,'Lucy', '2018-01-01')
INSERT INTO t1 values(3,'Tom', '2018-01-01')
INSERT INTO t2 values(2,'t2')
INSERT INTO t2 values(3,'t2')
select t1.* , t2.*
, CASE WHEN t2.user_id2 is null then 'the user is only in t1' ELSE 'the user is in both t1 and t2' end AS userCheck
from t1 left join t2 on t1.user_id1 = t2.user_id2