MySQL question - using IN()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Spidah

    MySQL question - using IN()

    Whey you use the IN() option in a mysql query is it possible to have the
    records selected in the order in which they appear in the IN string?

    Thanks

    Hamilton


  • Simon Stienen

    #2
    Re: MySQL question - using IN()

    Spidah <h.laughland@eg gstra.co.nz> wrote:[color=blue]
    > Whey you use the IN() option in a mysql query is it possible to have the
    > records selected in the order in which they appear in the IN string?
    >
    > Thanks
    >
    > Hamilton[/color]

    <http://dev.mysql.com/doc/mysql/en/String_function s.html>:
    FIELD() or FIND_IN_SET()
    --
    Simon Stienen <http://dangerouscat.ne t> <http://slashlife.de>
    »What you do in this world is a matter of no consequence,
    The question is, what can you make people believe that you have done.«
    -- Sherlock Holmes in "A Study in Scarlet" by Sir Arthur Conan Doyle

    Comment

    • Mike Edenfield

      #3
      Re: MySQL question - using IN()

      Spidah wrote:
      [color=blue]
      > Whey you use the IN() option in a mysql query is it possible to have the
      > records selected in the order in which they appear in the IN string?[/color]

      Something like this should work:

      SELECT ...
      FROM ...
      WHERE Field IN (x,y,z)
      ORDER BY CASE Field
      WHEN x THEN 1
      WHEN y THEN 2
      WHEN z THEN 3
      END

      --Mike

      Comment

      Working...