Basically I have a small ‘invoicing’ type system where I have a MySQL table set up for the individual invoices, the invoice lines, and items associated with each invoice, sort of like this:
table invoices:
fields: invoice_id | type | fees | comments | company
—
table invoice_lines:
fields: id | invoice_id | name | description | quantity
—
table invoice_affected_items
fields: id | invoice_id | item_id
I can have many invoice lines and many affected items to one invoice id. In this case would a join be best or should I just join the invoice lines to the table and retrieve the affected items using a separate query?
Thanks.
You could join, but that would result in pulling a lot of extra data. If you join the lines on to the invoices for example, you’d be pulling the invoice multiple times – once for each line…
So to answer your question. I’d do it in separate queries.