Home
Arjen's Journal - From normalised schema to spreadsheet
Open Query: MySQL, Open Source & other ponderings

Arjen Lentz
Date: 2008-05-11 22:55
Subject: From normalised schema to spreadsheet
Security: Public

Here's one for you... imagine you have a properly normalised schema, but you need to output it to CSV for a spreadsheet. So, you have multiple attributes for each item. The number of items is larger than the max # of joins (61) that you can do in MySQL. How to do this in a single query?

Post A Comment | 5 Comments | Add to Memories | Tell a Friend | Link



User: (Anonymous)
Date: 2008-05-11 17:41 (UTC)
Subject: Single Query Denormalization

I would not. I would take Kettle (http://kettle.pentaho.org/) and use the denormalization step to do it for me.

If you really want to, you can use SELECT's on GROUP_CONCAT and put that in the SELECT of your main query, but why annoy yourself? Life's too short to bother with SQL for this kind of thing anyway...

Roland Bouman

Reply | Thread | Link



User: (Anonymous)
Date: 2008-05-11 19:22 (UTC)
Subject: multiple attributes for each item

multiple attributes for each item? multiple rows in the csv

alternatively, use GROUP_CONCAT to make one row per item in the csv

where is the problem???

;o)


rudy
http://r937.com/

Reply | Thread | Link



Arjen Lentz
User: [info]arjen_lentz
Date: 2008-05-12 07:48 (UTC)
Subject: Re: multiple attributes for each item

If some questions have no answer, you'd still want a col... so you need to deal with a type of NULL situation.

Reply | Parent | Thread | Link



User: [info]brianpapantonio
Date: 2008-05-11 21:49 (UTC)
Subject: Pop quiz or real problem?

The pure MySQL way:

Use an IF() statement as a column for every attribute you wish to use. This is tedious to do, so use Peter Brawley's automatic pivot table stored procedure.

The easy way:

Use MS Excel to do one of the few things it's actually good for: Making Pivot Tables.

Reply | Thread | Link



User: (Anonymous)
Date: 2008-05-12 00:07 (UTC)
Subject: Also the Linux way :)

You can use one of the core util's for linux: join ; it's a great tool for joining large text based files and much faster than sql.
http://www-128.ibm.com/developerworks/linux/library/l-textutils.html#9

Reply | Thread | Link



browse
my journal
links
May 2008
High Performance MySQL (2nd ed.)
summary