获取记录时出现mysql错误

时间:2019-06-14 12:37:34

标签: php mysql

在加入SQL查询以获取记录时出现以下错误。

 #1066 - Not unique table/alias: 'v'

我在下面解释我的查询。

$sql="select v.owner_id,v.driver_id,v.reg_no,v.brand,v.model,v.vehicle_type,m.category_id,m.id,m.model_name,m.manufacture_id,m.image,mn.id,mn.manufacture_name,c.cat_id,c.category_name from cb_vehicle_info as v inner join cb_vechile_model as m on v.model=m.id inner join cb_vechile_manufacture as mn on m.manufacture_id=mn.id inner join cb_vechile_category v.vehicle_type=c.cat_id where v.driver_id=:driver_id and v.vehicle_type=:vehicle_type";

在这里,我要联接多个表以从表中获取记录,但是会引发上述错误。

1 个答案:

答案 0 :(得分:1)

我认为您省略了查询中的类别as c on

select
    v.owner_id,v.driver_id,v.reg_no,v.brand,v.model,v.vehicle_type,m.category_id,m.id,m.model_name,m.manufacture_id,m.image,mn.id,mn.manufacture_name,c.cat_id,c.category_name 
from 
    cb_vehicle_info as v 
inner 
    join cb_vechile_model as m on v.model=m.id 
inner 
    join cb_vechile_manufacture as mn on m.manufacture_id=mn.id 
inner join 
    cb_vechile_category as c on v.vehicle_type=c.cat_id 
where 
    v.driver_id=:driver_id 
and 
    v.vehicle_type=:vehicle_type