For Programmers: Free Programming Magazines  


Home > Archive > PHP SQL > September 2005 > Order By - problem









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Order By - problem
hamstring

2005-09-10, 6:56 pm

Is it possible to 'order by' 2 columns in a database

My database only has 2 columns.
1st column a bit of text
2nd column a int number
typically

COL1 COL2
AB 2
AZ 5
AF 1
AA 7
BC 5
AD 5

I want it sorted to
COL1 COL2
AA 7
AD 5
AZ 5
BC 5
AB 2
AF 1

Any ideas, as I can pnly get 1 column sorted ??
Anthony Frost

2005-09-10, 6:56 pm

In message <1cj6i1phm0l2cg5nh3gd6a511vahaeqfu7@4ax.com>
hamstring <agent@agent.com> wrote:

> Is it possible to 'order by' 2 columns in a database
>
> I want it sorted to
> COL1 COL2
> AA 7
> AD 5
> AZ 5
> BC 5
> AB 2
> AF 1


ORDER BY COL2, COL1

List the main column first, then the column to use if the entries in the
main column are the same.

Anthony

Andy Hassall

2005-09-10, 6:56 pm

On Sat, 10 Sep 2005 21:22:23 GMT, hamstring <agent@agent.com> wrote:

>Is it possible to 'order by' 2 columns in a database


Yes, "ORDER BY col1, col2".

>My database only has 2 columns.
>1st column a bit of text
>2nd column a int number
>typically
>
>I want it sorted to
>COL1 COL2
>AA 7
>AD 5
>AZ 5
>BC 5
>AB 2
>AF 1
>
>Any ideas, as I can pnly get 1 column sorted ??


Could you explain your logic behind the sort order you've specified?

It looks like: ORDER BY col2 DESC, col1

--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
hamstring

2005-09-11, 3:56 am

>
> Could you explain your logic behind the sort order you've specified?
>
> It looks like: ORDER BY col2 DESC, col1


Yip thats correct. Col1 is a list of words, and Col2 is how often they
occur.

I need to find the most common 15 words.

I then do a Select with a LIMIT 0, 15



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com