简体   繁体   中英

How do I query info from 2 tables based on 2 variables?

I'm trying to select all from the table Apparel_Colors where the value Apparel_Color_Palette within the Apparel_Colors table equals the value Apparel_Color_Palette within the Apparel table, in which the Apparel_ID within the Apparel table equals 1.

My bad pseudo logic query:

select * 
from Apparel_Colors 
where Apparel_Colors.Apparel_Color_Palette = Apparel.Apparel_Color_Palette 
AND Apparel.Apparel_ID = 1;

Basically, I only know the Apparel_ID. And, with the Apparel_ID I'm trying to get all the colors within the apparels color palette.

在此处输入图片说明

Any help is much appreciated.

select *
from apparel_colors
inner join Apparel_Color_Palette on apparel_colors.<field> = Apparel_Color_Palette.<field>
where Apparel.Apparel_ID = 1;

Showing us your table def would help.

Ok, with your table def, this is easy now. You have to join the 2 tables. You were not so far.

select *
from Apparel_Colors
inner join Apparel on Apparel_Colors.Apparel_Color_Palette = Apparel.Apparel_Color_Palette
where Apparel.Apparel_ID = 1;

Old syntax (very close to your query) :

select * from Apparel_Colors, apparel where Apparel_Colors.Apparel_Color_Palette = 
Apparel.Apparel_Color_Palette AND Apparel.Apparel_ID = 1;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM