QUERY PLAN
Limit (cost=12.65..12.66 rows=1 width=346)
-> Sort (cost=12.65..12.66 rows=1 width=346)
Sort Key: sci.from_date DESC, sci.created_at DESC
-> Group (cost=12.63..12.64 rows=1 width=346)
Group Key: sci.id
-> Sort (cost=12.63..12.64 rows=1 width=346)
Sort Key: sci.id
-> Seq Scan on tbl_sales_contract_invoices sci (cost=0.00..12.62 rows=1 width=346)
Filter: ((cover_invoice_id IS NULL) AND (contract_id = 8))