Jump to content


Photo

Who's Good At Joins?


  • Please log in to reply
2 replies to this topic

#1 lark

lark
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 29 June 2006 - 09:07 PM

I'm just learning how to do joins but am having trouble with this. I have two tables like this:

Table A

Title........ Category
Thing 1.........5
Thing 2.........5
Thing 3..........6
Thing 4........12

Table B

Category........Order
5....................13
6.....................20
12....................1

And I want to write a query that gives me this:

Title..............Category.........Order
Thing 1...........5....................13
Thing 2...........5.....................13
Thing 3...........6.....................20
Thing 4..........12.....................1

So each thing has a category. Each category has an order associated with it. I'd like to know the order of each thing based on its category. Make sense?

Thanks for your help!

#2 jworisek

jworisek
  • Members
  • PipPipPip
  • Advanced Member
  • 112 posts

Posted 30 June 2006 - 03:22 PM

I think you mean this right?

Select title, A.category, order from TableA A INNER JOIN TableB B ON (B.category=A.category) order by title ASC

//or it can also be written as:

Select title, A.category, order from TableA A, TableB B WHERE A.category=B.category order by title ASC


#3 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 03 July 2006 - 05:06 AM

Please use the JOIN syntax, not the theta syntax.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users