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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.