Jump to content

Who's Good At Joins?


lark

Recommended Posts

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!
Link to comment
https://forums.phpfreaks.com/topic/13252-whos-good-at-joins/
Share on other sites

I think you mean this right?

[code]
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
[/code]
Link to comment
https://forums.phpfreaks.com/topic/13252-whos-good-at-joins/#findComment-51275
Share on other sites

Archived

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

×
×
  • Create New...

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.