One to many too much data returned - MySQL
- by Evan McPeters
I have 2 related MySQL tables in a one to many relationship.
Customers: cust_id, cust_name, cust_notes
Orders: order_id, cust_id, order_comments
So, if I do a standard join to get all customers and their orders via PHP, I return something like:
Jack Black, jack's notes, comments about jack's 1st order
Jack Black, jack's notes, comments about jack's 2nd order
Simon Smith, simon's notes, comments about simon's 1st order
Simon Smith, simon's notes, comments about simon's 2nd order
The problem is that *cust_notes* is a text field and can be quite large (a couple of thousand words). So, it seems like returning that field for every order is inneficient.
I could use *GROUP_CONCAT* and JOINS to return all *order_comments* on a single row BUT order_comments is a large text field too, so it seems like that could create a problem.
Should I just use two separate queries, one for the customers table and one for the orders table?
Is there a better way?