I have tables in Oracle database: items (id, type, name) and contracts (id, item_id).
I want to select all items that is of type "sale" and have a contract OR all items that is of type "gift" (no matter contract here).
For this, I yped:
SELECT i.id, c.id as contract_id, i.type, i.name FROM items i, contracts c, -- others table WHERE -- some implicit joins AND ( (i.type = 'sale' AND c.item_id = i.id) OR (i.type = 'gift') ) This doesn't work.
How to select products of type "sale" and "gift" and join contracts only if type is "sale"?
JOINsyntax. Easier to write (without errors), easier to read (and maintain), and easier to convert to outer join if needed.pis not defined.