Show all relationships between two columns in MySQL
I have a single table that has data like the following:
Column 1 -- Column 2
A -- Z
A -- Y
B -- Y
I am looking for a way in MySQL to roll up this data so that I get the following table that will show group associations:
Column 1 -- Column 2
A,B -- Z,Y
I can use the group_concat function to get one column at a time grouped together, b开发者_如何学Gout I need both columns to be grouped to show the relationships. Any advice is greatly appreciated!
Try INFORMATION_SCHEMA.TABLE_CONSTRAINTS
and INFORMATION_SCHEMA.KEY_COLUMN_USAGE
. Reference : http://dev.mysql.com/doc/refman/5.0/en/key-column-usage-table.html
This will work.
select * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS;
精彩评论