我有个mysql问题。我有两张这样的桌子,我需要把它们连在一起。
表:
id otherid2
1-1-1
2/2-1
3/2
4×2
table2:
otherid otherid2
1-1-1
2/2-1
3/2
4×2
我在用:
SELECT id,otherid FROM table INNER JOIN table2 ON table.otherid2=table2.otherid2这给了我:
id otherid
1-1-1
1/2
2/2-1
2-2-2
3-3-3
3/4
4/3
4-4-4
如您所见,我得到了id的副本,因为otherid2s在table2中并不是唯一的。我需要的是内部连接在某种程度上是不同的,我只希望结果如下。不是重复的。
这就是我想要的:
id otherid
1-1-1
2/2-1
3-3-3
4×3
我能用简单的方式做这件事吗?
发布于 2010-10-04 11:32:56
在你的评论中,你想要最低的,然后我建议一个组和一个最小的聚合器。
SELECT id, MIN(otherid) AS otherid ... GROUP BY idhttps://stackoverflow.com/questions/3854714
复制相似问题