I'm writting a stored proc that has to query 2 tables. One table is a table of "jobs" and the other table contains jobs that have been invoiced (2 tables are jobs and invoicedJobs). The invoiced table only contains records for jobs that have an invoice and not jobs that do not have an invoice.
My dilemma is that I need to write a query that can retrieve allun-invoiced jobs in my stored proc. You can't rightly join a table that does not have a relationship with another table (can you?). So in my query for jobs with an invoice, I simply join my jobs table and invoice table based on a job id that both tables contain. But how could I perform a query for jobs thatdo not exist in my invoice table inside my stored proc? Any help would be greatly appreciated.
SELECT jobs.*
FROM jobs
LEFT JOIN invoices ON (jobs.id=invoiced.id)
WHERE invoiced.id IS NULL
or
SELECT *
FROM JOBS
WHERE id NOT IN (SELECT id FROM invoices)
Awsome. Thank you.
No comments:
Post a Comment