$sql =
"select
ls.id, ls.cat_id, ls.sub_id, rs.cat_name, lh.sub_cat_name,
ls.prod_name, ls.price, ls.availability, ls.description, ls.img_1,
ls.img_2, ls.img_3,ls.img_4, ls.img_5, ls.img_6, ls.img_7, ls.img_8,
ls.img_9, ls.img_10, ls.prod_order, ls.type
from product as ls
left join category as rs on rs.id = ls.cat_id
left join subcategory as lh on lh.id = ls.sub_id
where ls.id ='".$pid."'";
因此查询工作正常。所以我的问题是,这可以规范化为长度较短的查询吗?
答案 0 :(得分:-1)
您的查询
select
**
ls.id,
ls.cat_id,
ls.sub_id,
rs.cat_name,
lh.sub_cat_name,
ls.prod_name,
ls.price,
ls.availability,
ls.description,
ls.img_1,
ls.img_2,
ls.img_3,
ls.img_4,
ls.img_5,
ls.img_6,
ls.img_7,
ls.img_8,
ls.img_9,
ls.img_10,
ls.prod_order,
ls.type
**
from product as ls
left join category as rs
on rs.id = ls.cat_id
left join subcategory as lh
on lh.id ls.sub_id
where ls.id = {$pid};
因此,粗体字符(用** **包围)可以用ls代替。*表示已选择表中的所有属性,因此查询看起来像
select
ls.*
from product as ls
left join category as rs
on rs.id = ls.cat_id
left join subcategory as lh
on lh.id = ls.sub_id
where ls.id ='".$pid."'";