MySQL Forums
Forum List  »  General

Re: [Query help] Table transformation
Posted by: Rick James
Date: March 18, 2010 09:24PM

Is this any closer...
SELECT key,
       GROUP_CONCAT(eng SEPARATOR '') AS engName,
       GROUP_CONCAT(swe SEPARATOR '') AS sweName
    FROM
       ( SELECT key, name AS eng, CAST(NULL AS CHAR) AS swe
            FROM tbl
            WHERE locale = 'eng'
       )
       UNION
       ( SELECT key, CAST(NULL AS CHAR), name
            FROM tbl
            WHERE locale = 'swe'
       )
    GROUP BY key;

1. The inner SELECTs put the fields in the 'right' columns.
2. The UNION gets the eng and swe rows ready for the outer SELECT.
3. GROUP BY collects the pair (or single) rows.
4. The GROUP_CONCAT (I hope) finishes combining or leaving null.

COALESCE is another function to investigate.

Options: ReplyQuote


Subject
Written By
Posted
Re: [Query help] Table transformation
March 18, 2010 09:24PM


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.