How to Find Missing Value Between Two Mysql Tables

2020-02-15 01:43发布

select userid from cw_users where NOT EXISTS(Select userid from cw_users_data)

The previous query won't do the job of course.

Trying to find only a missing 'userid' from tableb by doing a comparison.

Both tables contain 'userid' and there should be one similar on each. I'm trying to find which one is missing on second table.

标签: php mysql sql
4条回答
甜甜的少女心
2楼-- · 2020-02-15 02:05

Try this

Select  userid from cw_users 
Except
Select userid from cw_users_data
查看更多
Ridiculous、
3楼-- · 2020-02-15 02:14
select userid from cw_users where userid not in(select userid from cw_users_data)
查看更多
我命由我不由天
4楼-- · 2020-02-15 02:17

Another method

SELECT cw_users.userid FROM cw_users
LEFT JOIN cw_users_data ON cw_users.userid=cw_users_data.userid
WHERE cw_users_data.userid IS NULL;
查看更多
家丑人穷心不美
5楼-- · 2020-02-15 02:20

how about this

select userid from cw_users where userid not in (Select userid from cw_users_data)
查看更多
登录 后发表回答