在内部联接查询中对数据排序

时间:2016-03-15 19:04:36

标签: mysql sql-order-by inner-join

select Distinct 
    _Ad.ad_id, _Ad.Ad_Name, 
    ID.Image_Path, VM.year, 
    VD.Vehicle_Transformation, VD.Vehicle_Fuel_Type, VD.Vehicle_Mileage
from 
    _Ad 
order by 
    Ad_Date_Created
inner join 
    _Image_Details ID on ID.ad_id = _Ad.ad_id 
inner join 
    _Vehicle_Model VM on VM.vehicle_model_id = _AD.vehicle_model_id 
inner join 
    _Vehicle_Details VD on _ad.ad_id = VD.ad_id;

我不断收到多部分数据无法绑定的错误。请帮助纠正查询

2 个答案:

答案 0 :(得分:0)

SQL语句的语法错误。 ORDER BY子句应该在JOIN的

之后

答案 1 :(得分:0)

试试这个:

select Distinct 
    _Ad.ad_id, _Ad.Ad_Name, 
    ID.Image_Path, VM.year, 
    VD.Vehicle_Transformation, VD.Vehicle_Fuel_Type, VD.Vehicle_Mileage
from 
    _Ad 
inner join 
    _Image_Details ID on ID.ad_id = _Ad.ad_id 
inner join 
    _Vehicle_Model VM on VM.vehicle_model_id = _AD.vehicle_model_id 
inner join 
    _Vehicle_Details VD on _ad.ad_id = VD.ad_id;
order by 
    Ad_Date_Created