[thelist] MySQL: from lookup tables to flat table

Matt Warden mwarden at gmail.com
Wed Apr 19 19:40:13 CDT 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

kasimir-k wrote:
> Dear List,
> 
> perhaps something simple, but today the answer just keeps escaping me.
> 
> I have tables
> persons - personId, name
> fields - fieldId, fieldName
> types - typeId, typeName
> persons_x_fields - personId, fieldId
> persons_x_types - personId, typeId
> 
> A person may belong to 0 or more fields and be of 0 or more types.
> 
> What kind of query would give a table like this:
> personId, name, [field1, field2, ...], [type1, type2, ...]
> 
> i.e. field and type columns are comma separated lists which can also be 
> empty.

http://r937.com/sqlate.cfm

Look for "Rows to columns (another "crosstab" report)"

- --
Matt Warden
Miami University
Oxford, OH, USA
http://mattwarden.com


This email proudly and graciously contributes to entropy.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFERthsrI3LObhzHRMRAlkCAJ0VaMoDXpHE/sOE1o0QFpjNO2Ru2gCdEf2Q
V0m3pRKnsC1SAXbPcIQi6TY=
=Gv1s
-----END PGP SIGNATURE-----



More information about the thelist mailing list