多张表联合查询时,多张表中包含相同字段,联合查询后相同的字段将会出现以下效果:
其中state,cid ,csid字段为重复字段,可以看出后面再次查询出的重复字段都加了尾缀1
QQ截图20181220093711.png
解决办法可以将重复字段起别名解决:
QQ截图20181220094051.png附加查询语句:
select product.csid as pcsid ,product.state as pstate,product.date as pdate,product.market_price,
product.pdesc,product.pid as ppid,product.pname,product.shop_price,product.stock,
category_floor.state as cstate ,category_floor.cid as cfcid ,category_floor.cname,category_floor.img,category_floor.state as cfstate ,
category_second_floor.cid as csfcid ,category_second_floor.csid,category_second_floor.csname,category_second_floor.state as csfstate,
image.date as imgdate ,image.image_id,image.`name` ,image.old_name,image.path,image.pid as imgpid ,image.state as imgstate
from category_floor
left join category_second_floor
on category_floor.cid = category_second_floor.cid
left join product
on category_second_floor.csid = product.csid
left join image
on product.pid = image.pid
select product.csid ,product.state as pstate,product.date as pdate,product.market_price,
product.pdesc,product.pid ,product.pname,product.shop_price,product.stock,
category_floor.state as cstate ,category_floor.cid ,category_floor.cname,category_floor.img,category_floor.state as cfstate ,
category_second_floor.cid ,category_second_floor.csid,category_second_floor.csname,category_second_floor.state as csfstate,
image.date as imgdate ,image.image_id,image.`name` ,image.old_name,image.path,image.pid ,image.state as imgstate
from category_floor
left join category_second_floor
on category_floor.cid = category_second_floor.cid
left join product
on category_second_floor.csid = product.csid
left join image
on product.pid = image.pid
select *
from category_floor
left join category_second_floor
on category_floor.cid = category_second_floor.cid
left join product
on category_second_floor.csid = product.csid
left join image
on product.pid = image.pid
网友评论