Results 1 to 3 of 3

Thread: Order results basing on IN Clause.

  1. #1

    Thread Starter
    Addicted Member Kamienios's Avatar
    Join Date
    Dec 2009
    Location
    Warsaw, Poland
    Posts
    159

    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

  2. #2
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    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.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  3. #3

    Thread Starter
    Addicted Member Kamienios's Avatar
    Join Date
    Dec 2009
    Location
    Warsaw, Poland
    Posts
    159

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width