in reply to Perl-MySQL get column names

"What I would like to do is to be able to tag the column name to the value for that column. For example:
item1 perl item2 python item3 ruby item4 php"

For mySQL, you can do it in this way:

SELECT concat('item1 ', item1) FROM basket WHERE item LIKE 'a%' UNION SELECT concat('item2 ', item2) FROM basket WHERE item2 LIKE 'a%' ORDER BY 1

For Oracle, I used to do:

SELECT 'item1 ' || item1 FROM basket WHERE item LIKE 'a%' UNION SELECT 'item2 ' || item2 FROM basket WHERE item2 LIKE 'a%' ORDER BY 1

Replies are listed 'Best First'.
Re^2: Perl-MySQL get column names
by Aighearach (Initiate) on Nov 07, 2004 at 20:35 UTC
    The Oracle one will work on PostgreSQL, too. I don't have the standards memorized, but it's probably SQL92 compliant, and should be very portable.

    --
    Snazzy tagline here
Re^2: Perl-MySQL get column names
by kiat (Vicar) on Nov 08, 2004 at 06:27 UTC
    Thanks, pg!

    I've tried it out and yes, I'm able to join the selected value to the column with your sql code using concat. It's what I was looking for.

    cheers