我真的很抱歉,我愿意编辑这个名字,不知道最好的方式来标题。
我有一个具有唯一值(组合名称)的表table_1 (1列),我正试图将其作为条件传递给另一个表table_2,该表包含两组UID (一个是组合UID,另一个是组件UID,两者都作为项在表3中),需要从第三个表table_3中提取table_1名称和table_2的UID。
我知道这真的很复杂!至少对我来说是..。
我的查询返回重复的信息,因为我认为我正在将相同的信息传递回它自己……
我的SQL如下所示:
Select i.item_id as Combo_kit_id, c.item_id as Component_item_id
from table_3 i
inner join table_1 t on i.item_id = t.item_id
inner join table_2 a on i.item_uid = a.assembly_uid
inner join table_3 c on a.component_uid = c.item_uidtable_1:
| item_ID |
----------
| CA123 |
| CA124 |
| CA125 |
| CA126 |
| CA127 |
| CA128 |
| CA129 |
---------table_2:
| assembly_UID | component_UID |
--------------------------------
| 1234 | 2234 |
| 1234 | 2235 |
| 1236 | 2236 |
| 1236 | 2237 |
| 1239 | 2238 |
| 1239 | 2239 |
| 1243 | 2242 |
| 1243 | 2288 |
--------------------------------table_3:
| item_ID | item_UID |
-------------------------
| CA123 | 1234 |
| CA124 | 1236 |
| CA125 | 1239 |
| CA126 | 1243 |
| CA127 | 2234 |
| CA128 | 2235 |
| CA129 | 2236 |
| CA130 | 2237 |
| CA131 | 2238 |
| CA132 | 2239 |
| CA133 | 2242 |
| CA134 | 2288 |
-------------------------我的结果是:
| Combo_kit_id | Component_item_id |
-----------------------------------
| CA123 | CA127 |
| CA123 | CA127 |
| CA123 | CA128 |
| CA123 | CA128 |
| CA124 | CA129 |
| CA124 | CA129 |
| CA124 | CA130 |
| CA124 | CA130 |
| CA125 | CA131 |
| CA125 | CA131 |
| CA125 | CA132 |
| CA125 | CA132 |
------------------------------有没有办法不去获取添加的副本?
发布于 2018-07-21 05:38:00
你不能直接使用distinct吗
Select distinct i.item_id as Combo_kit_id, c.item_id as Component_item_id
from table_3 i
inner join table_1 t on i.item_id = t.item_id
inner join table_2 a on i.item_uid = a.item_uid
inner join table_1 c on a.component_uid = c.item_uidhttps://stackoverflow.com/questions/51450662
复制相似问题