Data Manipulation in a query

Discussion in 'MySQL' started by Jamie18, Jun 27, 2007.

  1. #1
    hey, just wondering if anyone can give me a quick answer to this.

    Is there a way to change values returned by a query into something else during the query process.. well that wasn't the clearest statement i've ever made so i'll put down an example..

    say we are working with something like this

    SELECT account_number, account_type
    FROM bankaccounts

    and account_type is a value between 1 and 3
    what i want to do is instead of getting a result set like this

    account_number | account_type
    0923423234 1
    2834203443 1
    0230489453 3
    ...

    i want

    account_number | account_type
    0923423234 savings
    2834203443 savings
    0230489453 chequeing
    ...

    so what i'm looking for is a way to incoporate something that would be the equivalent of

    if account_type.value = 1 set account_type.value = 'savings' .. etc.

    but i don't want to modify the database
     
    Jamie18, Jun 27, 2007 IP
  2. gibex

    gibex Active Member

    Messages:
    1,060
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    95
    #2
    what mysql do you have?
     
    gibex, Jun 27, 2007 IP
  3. Clark Kent

    Clark Kent Guest

    Messages:
    122
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #3
    you can use "case when" statement.

    Simple example:
    select case number_field when 1 then 'one' when 2 then 'two' when 3 then 'three' end
    from number_table
     
    Clark Kent, Jun 27, 2007 IP
    Jamie18 likes this.
  4. Jamie18

    Jamie18 Peon

    Messages:
    201
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    works like a dream, thanks super
     
    Jamie18, Jun 27, 2007 IP