the scenario is as follows:
I have an invoice and supplier table. The invoice references supplier on supplier_id. I want to insert into invoice. If supplier_company does not exist in the supplier table, first insert into supplier then use the new supplier_id in invoice, else use the supplier_id of the matching supplier_name.
I've managed to get here:
insert into supplier (supplier_company) select ('Company Name') where not exists (select 1 from supplier where supplier_company='Company Name');
insert into invoice (invoice_number, supplier_id) values (xxx, (select supplier_id from supplier where supplier_company = 'Company Name')
but I was wondering if there's a cleaner, clearer way to express this in one expression.
Thank you for your time.