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 > Rename variable in select statement?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-20-10, 05:43
gsmdude gsmdude is offline
Registered User
 
Join Date: Apr 2010
Posts: 1
Rename variable in select statement?

I'm trying to temporarily rename a variable in my select statement for sorting. For instance, "Research in Motion" is the company name, but I'd like to replace it as "BlackBerry" to sort so the output is, say:

Apple
BlackBerry
Motorola
Samsung

Is there a command that can let me do this without replacing the actual value? Thanks.
Reply With Quote
  #2 (permalink)  
Old 04-20-10, 06:48
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
use a CASE expression
Code:
SELECT CASE WHEN company = 'Research in Motion'
            THEN 'Blackberry'
            ELSE company END AS temp_company
  FROM ...
ORDER
    BY temp_company
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
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