Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 两个结果集之间的差异_Mysql - Fatal编程技术网

Mysql 两个结果集之间的差异

Mysql 两个结果集之间的差异,mysql,Mysql,这是一个非常初级的问题,但在阅读了各种帮助资源后,还没有找到答案 我有一个表组,它是表用户和组之间的连接表。相关列:Id,用户Id,组Id。我正在做一项数据清理工作,根据一个位置为用户分配了一个组id,该位置过去是一个城市的3个字符缩写,但后来用于拼写完整的城市(例如:以前为CHA分配了组id,现在为Charlotte分配了组id)。大多数用户目前都有与其用户id关联的组ids,但有些用户仍然只有旧的组id,并且从未分配过新的组id 查找此结果集中的ID的最有效方法是什么: select use

这是一个非常初级的问题,但在阅读了各种帮助资源后,还没有找到答案

我有一个表组,它是表用户和组之间的连接表。相关列:
Id
用户Id
组Id
。我正在做一项数据清理工作,根据一个位置为用户分配了一个组id,该位置过去是一个城市的3个字符缩写,但后来用于拼写完整的城市(例如:以前为CHA分配了
组id
,现在为Charlotte分配了
组id
)。大多数用户目前都有与其用户id关联的
组id
s,但有些用户仍然只有旧的
组id
,并且从未分配过新的组id

查找此结果集中的ID的最有效方法是什么:

select user_id from group_affiliations where group_id=OldId;
select user_id from group_affiliations where group_id=NewId;
但不在此结果集中:

select user_id from group_affiliations where group_id=OldId;
select user_id from group_affiliations where group_id=NewId;

使用
JOIN

SELECT g1.'user_id' 
from 'group_affiliations' g1
inner join 'group_affiliations' g2 
on g2.'group_id' != NewId
and g2.'group_id' = OldId
and g1.'user_id'=g2.'user_id'

OldId
NewId
字段是否位于
集团附属机构上?如果是,如果未分配
NewId
,它会为空吗?你能给问题添加一些示例数据吗?对不起,应该更清楚一些。OldId和NewID不是字段。我只是把它们当作占位符。