Jump to content

Ordering results


The Little Guy

Recommended Posts

I though I have done something similar to this query in the past:

 

SELECT * FROM docs WHERE (`type` = 'method' OR `type` = 'property') AND `class` = 'Nebala' ORDER BY `type` ORDER BY `title`

 

I am getting an error with my second ORDER BY, but for some reason I though I have done that in the past.

 

My table has a few columns, but I want to do is get anything from the table where the type is either property or method, I want all properties to display first then the methods in the returned result. I then want to order the titles in alphabetical order in those two groups.

so...

 

- properties:

abc

cat

url

 

- methods

another

fisrt

second

version

 

as you can see properties come first and are listed in abc order in that group, and then methods come next which are in abc order in that group as well.

 

So what am I doing wrong, I am stumped!

Link to comment
https://forums.phpfreaks.com/topic/187814-ordering-results/
Share on other sites

You only need ORDER BY once, but you can specify multiple columns...

 

SELECT * FROM docs WHERE (`type` = 'method' OR `type` = 'property') AND `class` = 'Nebala' ORDER BY `type`, `title`

 

Just add in ASC or DESC as required after the column names in the ORDER BY section

Link to comment
https://forums.phpfreaks.com/topic/187814-ordering-results/#findComment-991637
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.