help with query

This is a discussion on help with query within the MySQL Database forums, part of the Database Forums category; select number,name,age,address from people where number in (88,4,2,6,8,1,166,33) How I ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-16-2007
Aahz
 
Posts: n/a
Default help with query

select number,name,age,address from people
where number in (88,4,2,6,8,1,166,33)

How I make this to have order by exact numbers as in query. I want
result to be ordered like this:

88
4
2
6
8
1
166
33

and not

1
2
4
......etc

and not by name or anything else

How to do this ? Thank you

Reply With Quote
  #2 (permalink)  
Old 05-16-2007
Captain Paralytic
 
Posts: n/a
Default Re: help with query

On 16 May, 09:55, Aahz <juno10...@hotmail.com> wrote:
> select number,name,age,address from people
> where number in (88,4,2,6,8,1,166,33)
>
> How I make this to have order by exact numbers as in query. I want
> result to be ordered like this:
>
> 88
> 4
> 2
> 6
> 8
> 1
> 166
> 33
>
> and not
>
> 1
> 2
> 4
> .....etc
>
> and not by name or anything else
>
> How to do this ? Thank you


SELECT
`number`,
`name`,
`age`,
`address`
FROM `people`
WHERE `number` IN (88,4,2,6,8,1,166,33)
ORDER BY FIND_IN_SET(`number`,'88,4,2,6,8,1,166,33')

Reply With Quote
  #3 (permalink)  
Old 05-16-2007
Aahz
 
Posts: n/a
Default Re: help with query

Thank you Captain !

Captain Paralytic je napisao:
> On 16 May, 09:55, Aahz <juno10...@hotmail.com> wrote:
> > select number,name,age,address from people
> > where number in (88,4,2,6,8,1,166,33)
> >
> > How I make this to have order by exact numbers as in query. I want
> > result to be ordered like this:
> >
> > 88
> > 4
> > 2
> > 6
> > 8
> > 1
> > 166
> > 33
> >
> > and not
> >
> > 1
> > 2
> > 4
> > .....etc
> >
> > and not by name or anything else
> >
> > How to do this ? Thank you

>
> SELECT
> `number`,
> `name`,
> `age`,
> `address`
> FROM `people`
> WHERE `number` IN (88,4,2,6,8,1,166,33)
> ORDER BY FIND_IN_SET(`number`,'88,4,2,6,8,1,166,33')


Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 05:22 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0