I have a .csv file with data records, each line containing departments of organisations. I would like to import them into a MySQL database and show them in a web application. A sample abstract of data records looks like this:
| Company A | Department aaa |
| Company A | Department bbb |
| Company A | Department ccc |
| Company B | Department ddd |
| Company B | Department eee |
| Company C | Department fff |
| Company C | Department ggg |
| Company C | Department hhh |
| Company D | Department iii |
| Company E | Department jjj |
| Company E | Department kkk |
Of course I want to show each company once with its related departments attached, which makes it look this way, more or less:
| Company A | Department aaa |
| | Department bbb |
| | Department ccc |
| Company B | Department ddd |
| | Department eee |
| Company C | Department fff |
| | Department ggg |
| | Department hhh |
| Company D | Department iii |
| Company E | Department jjj |
| | Department kkk |
My question is, what is the best way to concatenate these data records? Would you do it using the appropriate programing language (ie PHP, Ruby, Perl, whatever) or would you do it in the database using SQL query? If SQL is the choice, would you do it using stored procedures, temp tables, or even at the import interface? What would it look like if it was SQL? Thank you!