Hello. Something Friday seems to have an effect.
There is a table of invoices for payment (invoices) and their payments (payments). One invoice for payment can be paid in several payments.
Tables:invoices - id (int), ...payments - id (int), invoice_id (int), method (enum Wire, PayPal, Webmoney) ...
You need to get invoices containing for example PayPal, but you need to pick up all payments.
Those.
SELECT invoices.id AS invoice_id, GROUP_CONCAT(payments.method) AS methods, ... FROM invoices LEFT OUTER JOIN payments ON payments.invoice_id = invoices.id GROUP BY invoices.id HAVING GROUP_CONCAT(payments.method) LIKE '%PayPal%' As a result, we obtain a table of invoices and by what methods each record is paid.
UPD: add sqlfiddle: http://sqlfiddle.com/#!9/d6a33d/1
Confused by LIKE in the condition of HAVING. How to do without it in this request?