If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > ORDER BY value of index - not position

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-05-06, 06:09
anjanesh anjanesh is offline
Registered User
 
Join Date: Feb 2005
Location: Mumbai, India
Posts: 161
ORDER BY value of index - not position

I have a MySQL query
Code:
SELECT `Id`, `Info` 
FROM `tbl1` 
WHERE `Id` = 5 OR `Id` = 1 OR `Id` = 3
I want it returned as
Code:
5, info5
1, info1
3, info3
Im not looking for position - position looks at the order of Id - Im looking for the value of Id.
Is there any way to accomplish this ? Or would I need to execute 3 separate queries ?

Thanks
Reply With Quote
  #2 (permalink)  
Old 03-05-06, 06:23
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Code:
select id
     , info 
  from tbl1 
 where id in (5,1,3)
order
    by field(id,5,1,3)
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 03-05-06, 06:47
anjanesh anjanesh is offline
Registered User
 
Join Date: Feb 2005
Location: Mumbai, India
Posts: 161
Cannot believe I skipped this from the manual.
Thanks r937 - you've always been prmopt and helpful. Your time here is truly appreciated.

Strange though - it works in phpMyAdmin but not my PHP script
FUNCTION db1.FIELD does not exist
I have in m script
Code:
$Res = mysql_query($SQL) or die("\n<!--$SQL-->\n".mysql_error());
I exectued what was inbetween <!-- and --> and worked !

Last edited by anjanesh; 03-05-06 at 07:08.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

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