Order results basing on IN Clause.
Hi,
I'd been searching a little about that case but didn˛t find an answer.
I have a query, eg:
Select * from items where itemCode in(32123,321259,12489,45896)
I would like to have a result ordered in the same order in which i put items code to IN clause.
Is that possible? I`ve been thinking about creating programatically in .NET a SQL query made with UNION like:
Select * from items where itemcode = 32123
UNION
Select * from items where itemcode = 321259
etc.
The result will be as expected, but I think this will load a database too much for a bigger amount of items.
Thanks for Your help.
Peter
Re: Order results basing on IN Clause.
You haven't mentioned what RDBMS you are using.
In SQL Server you can insert the filters in a temporary table. The temporary table should have a auto-increment primary key.
Then inner join that temporary table with your main table on the "itemcode" field and oder by the auto-id field.
Re: Order results basing on IN Clause.
Sorry, my fault.
I use Ms SQl Server 2008 R2.
Thanks for the tip -I`ll try this way.
Thanks