Page 1 of 1

2 Table MySql Query Assist

Posted: Sun Jul 05, 2009 9:20 pm
by tjhopkinson
Kind gentlemen / ladies,

Here are the two tables I am working with ... the important columns at least --

Table #1 - items (catid -- which contains the ID# of whatever category it is from table #2)
Table #2 - categories (id,name)

I want to be able to display a search results page that allows me to sort in alphabetically ascending order all the pertinent information from Table #1 but based on the NAME column from Table #2.

So basically:

Select everything from items,categories order by categories name

Any assistance would be greatly appreciated, thanks.

Re: 2 Table MySql Query Assist

Posted: Sun Jul 05, 2009 11:10 pm
by califdon

Code: Select all

SELECT * FROM [i]items[/i] JOIN [i]categories[/i] ON categories.id=items.id
   ORDER BY name
should do it.

Re: 2 Table MySql Query Assist

Posted: Sun Jul 05, 2009 11:21 pm
by jackpf
Something like

Code: Select all

SELECT X.*, Y.`Name` AS `Name`
FROM tbl1 X
INNER JOIN tbl2 Y ON X.`Catid`=Y.`ID`
GROUP BY tbl2.`Catid`
ORDER BY `Name` ASC
If not, it's something like that.