Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

This question already has an answer here:

I have this table:

Name    Address                  Code
James   CT                       Homeaddress
Mark    mark@goole.com           Email
John    John@hotmail.com         homeemail
...

This is what I want:

Name        Homeaddress      Email           homeemail
james       CT
mark                         mark@google.com
john                                         John@hotmail.com

I am creating a view and dont have privilages to alter the base tables. I was thinking maybe an IF statement might help

share|improve this question

marked as duplicate by Jon Seigel, RolandoMySQLDBA, Aaron Bertrand Jul 19 '13 at 17:05

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
ITS KIND OF DIFFERENT AS I DONT HAVE ANY NUMBERS –  Rafey Jul 19 '13 at 16:40

1 Answer 1

up vote 1 down vote accepted

I think you can use CASE expression. Something like that:

SELECT Name,
  CASE Code WHEN 'Homeaddress' THEN Address ELSE NULL END AS Homeaddress,
  CASE Code WHEN 'Email' THEN Address ELSE NULL END AS Email,
  CASE Code WHEN 'homeemail' THEN Address ELSE NULL END AS homeemail
FROM yourtable
share|improve this answer
    
Thanks Mindaugas! It worked!! –  Rafey Jul 19 '13 at 17:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.