Asistencia con 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 know 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 :

enter image description here

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.

preguntado el 27 de agosto de 11 a las 16:08

3 Respuestas

Prueba esto:

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

Si tu no sabes 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

Respondido 27 ago 11, 20:08

thank you I think that will be working right ... I've forgotten all these issues about two tables with n-n relations +1 ;) - SmootQ

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

Respondido 27 ago 11, 20:08

Tratar:

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

¿Fue eso?

And also try to study SQL a little bit.

Respondido 27 ago 11, 20:08

yeah , I've studied sql for 1 year.. But the problem is that I gave up the domain for months , so I did forget many issues :( thank you all, I remember now - SmootQ

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.