gpt4 book ai didi

mysql - 仅两个表之间的多重联接

转载 作者:行者123 更新时间:2023-11-29 12:23:33 24 4
gpt4 key购买 nike

表1:key_item#、code_1、code_2、code_3

表2:uniq_code、code_desc

表1:

key_item#  code_1  code_2  code_3
1 Y01 M02 X01
2 Y01 M04 X01

表2:

uniq_code      code_desc
Y01 DescriptionY01
M02 DescriptionM02
X01 DescriptionX01
M04 DescriptionM04

更好的图像细节 https://dl.dropboxusercontent.com/u/9951225/Untitled-4.jpg

查询结果

key_item#   code_1     code_desc      code_2        code_desc    cod_3    code_desc
1 Y01 DescriptionY01 M02 DescriptionM02 X01 DescriptionX01
2 Y01 DescriptionY01 M04 DescriptionM04 X01 DescriptionX01

查询

SELECT     Table1.key_item#,
Table1.code_1,
Table2.code_desc,
Table1.code_2,
Table2.code_desc,
imc_iamerican_claim_lines.Add_diagnosis1

FROM msp_dx9_priority.dx09code_matrix
INNER JOIN Table1 ON Table1.code_1 = Table2.uniq_code
INNER JOIN Table1 ON Table1.code_2 = Table2.uniq_code

我无法解决“表别名不唯一”错误

最佳答案

您需要为联接添加别名,以便查询引擎知道如何消除第一个 Table1 和第二个 Table1 的歧义。此处的文档:http://dev.mysql.com/doc/refman/5.0/en/join.html

这是一个例子:

SELECT     Table1.key_item#, -- which join should this come from? code1 or code2?
t1_code1.code_1,
Table2.code_desc, -- don't know what is Table2, perhaps t1_code1?
t1_code2.code_2,
Table2.code_desc, -- don't know what is Table2, perhaps t1_code2?
imc_iamerican_claim_lines.Add_diagnosis1 -- also don't know what this is :)

FROM msp_dx9_priority.dx09code_matrix
INNER JOIN Table1 t1_code1 ON t1_code1.code_1 = Table2.uniq_code
INNER JOIN Table1 t1_code2 ON t1_code2.code_2 = Table2.uniq_code

关于mysql - 仅两个表之间的多重联接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28680838/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com