php MySql使用表连接表。名称与Table.B列名匹配

时间:2017-08-15 21:40:44

标签: php mysql

我已经尝试了我能想到的一切。问题。主表具有与第二个表名匹配的列。我不能加入。有什么帮助吗?

SELECT 
    Inspections.Id,
    Inspections.Custom_Specs,
    Custom_Specs.Id AS Custom_Id                
FROM Inspections
    JOIN Custom_Specs ON Inspections.Custom_Specs=Custom_Specs.Id

Inspections.Id,           (Value: 1)
Inspections.Custom_Specs, (Value: 5)
Custom_Specs.Id,          (Value: 5)
Custom_Specs.Spec_Name ,   (Value: Name Of Spec)
Custom_Specs.Id AS Specs_Id

输出:

<option value=\"". $row["Specs_Id."] ."\">". $row["Spec_Name"] ."</option>

更新:

查询哪个对我有用:

SELECT 
   Inspections.Id, 
   Inspections.Custom_Specs, 
   Custom_Specs.Id, 
   Custom_Specs.Spec_Name
FROM Inspections 
LEFT JOIN Custom_Specs ON Inspections.Custom_Specs = Custom_Specs.Id

1 个答案:

答案 0 :(得分:0)

您将规格与ID列进行比较。这是两种不同的数据类型。下面的查询应该为您完成工作:

SELECT 
   Custom_Specs.Id
   Custom_Specs.Spec_Name
FROM Inspections
LEFT JOIN Custom_Specs ON Inspections.Custom_Specs = Custom_Specs.Id