我正在尝试执行以下查询:
SELECT g1.Name_Gene as "Name_ref"
, g1.Type_Gene
, gr.Class_Name
, g2.Name_Gene as "Name_avr"
, path.Name_SpeciePa
, dis.Name_Disease
, g1.Id_Genes as "Id_ref"
, g2.Id_Genes as "Id_avr"
, dis.Id_Diseases
, path.Id_Pathogens
FROM plants_genes as pg
, genes_reference as gr
, genes as g1
LEFT JOIN avirulence_reference as ar ON (g1.Id_Genes=ar.Id_Genes_ref)
LEFT JOIN genes as g2 ON (ar.Id_Genes_avr=g2.Id_Genes)
LEFT JOIN reference_diseases as rd ON (gr.Id_Genes=rd.Id_Genes)
LEFT JOIN pathogens_diseases as pd ON (rd.Id_Diseases=pd.Id_Diseases)
LEFT JOIN diseases as dis ON (pd.Id_Diseases=dis.Id_Diseases)
LEFT JOIN pathogens as path ON (pd.Id_Pathogens=path.Id_Pathogens)
WHERE pg.Id_Plants='196' AND pg.Id_Genes=g1.Id_Genes AND g1.Id_Genes=gr.Id_Genes
我收到了这个错误:
ERROR 1054(42S22):未知栏' gr.Id_Genes'在' on条款'
我不明白为什么会收到此错误,因为genes_reference
定义为gr
且Id_Genes
是现有列。
答案 0 :(得分:2)
这是因为您混合了隐式和显式连接符号:
FROM genes as g1
JOIN genes_reference as gr on g1.Id_Genes=gr.Id_Genes
JOIN plants_genes as pg on pg.Id_Genes=g1.Id_Genes
<...>
WHERE pg.Id_Plants='196'
答案 1 :(得分:0)
你应该改变你的内部联接: FROM plants_genes as pg 加入genes_reference作为gr on({common keys}) 将基因作为g1加入({common keys})