"SELECT number,
CASE company WHEN ' '
THEN (SELECT CONCAT(firstname, ' ', lastname)
FROM tblcontacts WHERE userid = tblclients.userid and is_primary = 1)
ELSE company
END as company,
date, subtotal, total, total_tax,
discount_total, adjustment,
status ,userid,project_id,clientid,tblinvoices.id,discount_percent,deleted_customer_name,
tblitemable.*
FROM tblinvoices
LEFT JOIN tblclients ON tblclients.userid = tblinvoices.clientid
LEFT JOIN tblitemable ON tblinvoices.id = tblitemable.rel_id
WHERE date BETWEEN ""2022-09-01"" AND ""2022-11-30"" AND tblitemable.rel_type = 'invoice'
ORDER BY date DESC, number DESC;"
Observaciones técnicas
"SELECT number, CASE company WHEN ' ' THEN (SELECT CONCAT(firstname, ' ', lastname) FROM tblcontacts WHERE userid = tblclients.userid and is_primary = 1) ELSE company END as company, date, subtotal, total, total_tax, discount_total, adjustment, status ,userid,project_id,clientid,tblinvoices.id,discount_percent,deleted_customer_name, tblitemable.* FROM tblinvoices LEFT JOIN tblclients ON tblclients.userid = tblinvoices.clientid LEFT JOIN tblitemable ON tblinvoices.id = tblitemable.rel_id