MySQL Forums
Forum List  »  General

transpose rows into columns
Posted by: Christian Meyer
Date: July 12, 2009 07:55AM

Hi,

in an existing db addresses (mail, phone, mobile) are stored in the same column, marked by a contacttype attribute:

id----address--------------contacttype_id-----person_id
1-----mysql@mysql.com--1--------------------1
2-----001783748483-----3--------------------1
3-----mysql@sun.com----1--------------------2
4-----0093949394493----2--------------------1

Where contacttype 1 mail, 2 mobile, 3 landline.

I would like to get the following output:

person_id-------mail-----------------phone-------------mobile
1----------------mysql@mysql.com---001783748483--0093949394493

I tried the following query, but it both columns the mail address appear:

SELECT m.address as mail, p.address as phone FROM contact m
INNER JOIN contact p on m.id = p.id WHERE m.contacttype_id = "1" OR p.contacttype_id = "2"

Any help is very appreciated,

many thanks

Christian



Edited 3 time(s). Last edit at 07/12/2009 09:16AM by Christian Meyer.

Options: ReplyQuote


Subject
Written By
Posted
transpose rows into columns
July 12, 2009 07:55AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.