explain SELECT aqinvoices.*, aqbooksellers.name AS suppliername, COUNT( DISTINCT IF( aqorders.datereceived IS NOT NULL, aqorders.biblionumber, NULL ) ) AS receivedbiblios, COUNT( DISTINCT IF( aqorders.subscriptionid IS NOT NULL, aqorders.subscriptionid, NULL ) ) AS is_linked_to_subscriptions, SUM(aqorders.quantityreceived) AS receiveditems FROM aqinvoices LEFT JOIN aqbooksellers ON aqbooksellers.id = aqinvoices.booksellerid LEFT JOIN aqorders ON aqorders.invoiceid = aqinvoices.invoiceid LEFT JOIN aqbasket ON aqbasket.basketno=aqorders.basketno LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber LEFT JOIN biblio ON aqorders.biblionumber = biblio.biblionumber LEFT JOIN biblioitems ON biblio.biblionumber = biblioitems.biblionumber LEFT JOIN subscription ON biblio.biblionumber = subscription.biblionumber WHERE aqinvoices.booksellerid = '7' GROUP BY aqinvoices.invoiceid ORDER BY shipmentdate desc; +------+-------------+---------------+--------+------------------------------+------------------------------+---------+------------------------------------+------+-------------------------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +------+-------------+---------------+--------+------------------------------+------------------------------+---------+------------------------------------+------+-------------------------------------------------+ | 1 | SIMPLE | aqinvoices | ref | aqinvoices_fk_aqbooksellerid | aqinvoices_fk_aqbooksellerid | 4 | const | 231 | Using temporary; Using filesort | | 1 | SIMPLE | aqbooksellers | eq_ref | PRIMARY | PRIMARY | 4 | vaara_koha.aqinvoices.booksellerid | 1 | | | 1 | SIMPLE | aqorders | ref | aqorders_ibfk_3 | aqorders_ibfk_3 | 5 | vaara_koha.aqinvoices.invoiceid | 10 | | | 1 | SIMPLE | aqbasket | eq_ref | PRIMARY | PRIMARY | 4 | vaara_koha.aqorders.basketno | 1 | Using where | | 1 | SIMPLE | biblio | eq_ref | PRIMARY,blbnoidx | PRIMARY | 4 | vaara_koha.aqorders.biblionumber | 1 | Using where; Using index | | 1 | SIMPLE | biblioitems | ref | bibnoidx | bibnoidx | 4 | vaara_koha.biblio.biblionumber | 1 | Using where; Using index | | 1 | SIMPLE | subscription | ALL | NULL | NULL | NULL | NULL | 6144 | Using where; Using join buffer (flat, BNL join) | +------+-------------+---------------+--------+------------------------------+------------------------------+---------+------------------------------------+------+-------------------------------------------------+