Jump to content

Archived

This topic is now archived and is closed to further replies.

jwwceo

Join tables queries are confusing???

Recommended Posts

I have a databse with three tables. shirts, colors, and shirtcolors. Shirtcolors has 2 fields for the primary keys for both shirts and colors, linking up shirts and what colors thet come in...

my customers are going to be selecting a color from a pulldown and I want to have a search results page display all the shirts that have that color...

I have never pulled data from 2 tables before...what's the best way to do this????

Share this post


Link to post
Share on other sites
[code][code]Use a join...

http://dev.mysql.com/doc/refman/5.0/en/join.html

[/code]SELECT * FROM shirtcolors
  LEFT JOIN colors ON shirtcolors.color_id = colors.color_id
  LEFT JOIN shirts ON shirtcolors.shirt_id = shirts.shirt_id
WHERE color = 'Blue';[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.