开发者

Assistance with SELECT

I have three tables: hosting_pack, hosting_attr and hosting_attr_value.

One hosting_category can have many hosting_packs and many hosting_attributes.

To know the hosting_value, we must kno开发者_JAVA技巧w the hosting_pack and the hosting_attribute, so hosting_pack contains the pack information, hosting_attr contains the attributes, and hosting_attr_value contains the values of every attribute in one pack.

Described as follows :

Assistance with SELECT

I want to display a table like this:

hosting_attr,          hosting_attr_value ,           for a given id_hosting_pack

Note: the relation between hosting_categ and hosting_attr doesn't exist, just ignore it.


Try this:

select hosting_attr.attr_label, hosting_attr_value.hosting_attr_value from hosting_attr_value, hosting_attr where hosting_attr_value.id_hosting_pack = ? and hosting_attr.id_hosting_attr = hosting_attr_value.id_hosting_attr

If you do not know id_hosting_pack, you can look it up in-line

select hosting_attr.attr_label, hosting_attr_value.hosting_attr_value from hosting_attr_value, hosting_attr where hosting_attr_value.id_hosting_pack = (select id_hosting_pack from hosting_pack where pack_name = ?) and hosting_attr.id_hosting_attr = hosting_attr_value.id_hosting_attr


select ha.attr_label, hav.attr_value from hosting_attr ha
inner join hosting_attr_value hav on ha.id_hosting_attr = hav.id_hosting_attr
where hav.id_hosting_pack = :theIdOfTheHostingPack


Try:

select *
from 
 hosting_pack hp,
 hosting_attr_value hav,
 hosting_attr ha
where
    hp.id_hosting_pack = hav.id_hosting_pack
and hav.id_hosting_attr = ha.id_hosting_attr

Was that it?

And also try to study SQL a little bit.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜