SELECT
 a.id AS `Account ID`,
 c.name AS `Category Name`,
 p.name AS `Product Name`,
 a.status AS `Account Status`,
 a.next_due AS `Account next due date`

FROM hb_accounts a
 JOIN hb_products p ON (p.id=a.product_id)
 JOIN hb_categories c ON (c.id=p.category_id)
WHERE
 a.status NOT IN ('Terminated','Cancelled','Fraud','Pending')
AND
 a.billingcycle NOT IN ('Free','One Time')
AND
 a.id IN (
 SELECT it.item_id FROM hb_invoice_items it JOIN hb_invoices i ON (i.id=it.invoice_id)
 WHERE it.type='Hosting' AND i.status='Unpaid'
)