我正在尝试为多对多关系运行查询,我创建了一个联结表来执行此操作。现在,当我期望为每个索引122,123,124返回3行时,我遇到了没有结果的问题,有人能指出我的错误,谢谢
SELECT * FROM [Moldingdata].[dbo].[mach_part_junction] ORDER BY [machinename] ASC
SELECT MachineList.machinename ,JDEPARTIMGLU.Jde_part_num
from mach_part_junction
INNER JOIN MachineList on mach_part_junction.machinename = machinelist.Machine_ID
INNER JOIN JDEPARTIMGLU on mach_part_junction.machinename = machinelist.Machine_ID
WHERE mach_part_junction.machinename= 'MM01'
结果:
machinename ndx_jde_part_img
----------- ----------------
MM01 122
MM01 123
MM01 124
MM04 122
MM15 124
MM17 122
MM32 122
MM32 123
(8 row(s) affected)
machinename Jde_part_num
----------- --------------------
(0 row(s) affected)
答案 0 :(得分:1)
第二张和第三张桌子上的连接条件是相同的。
看起来第三个表的连接条件是需要更改的条件。
答案 1 :(得分:0)
当我对此类查询进行疑难解答时,我通常会执行以下操作:
SELECT *
FROM mach_part_junction
INNER JOIN MachineList on mach_part_junction.machinename = machinelist.Machine_ID
然后我添加下一个JOIN:
SELECT *
FROM mach_part_junction
INNER JOIN MachineList on mach_part_junction.machinename = machinelist.Machine_ID
INNER JOIN JDEPARTIMGLU on mach_part_junction.machinename = machinelist.Machine_ID
然后是WHERE(如果表格不是太大)
这样你就可以看到发生了什么。