Jump to content


Photo

Join tables queries are confusing???


  • Please log in to reply
1 reply to this topic

#1 jwwceo

jwwceo
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts

Posted 28 August 2006 - 09:25 PM

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????

#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 28 August 2006 - 09:41 PM

[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';





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users