I have 3 different tables: table1, table2, table3
Table 1 contains all the different orders that were purchased
Table 2 contains the detail of every order (i mean, it contains a column called ORDER_DETAIL and the number represent an item of that order -a unique value)
Table 3 contains the workflow.. some numbers that were inside ORDER_DETAIL from Table 2 will appear here because this item must be approved to be delivered
I want to obtain all the different orders whose items did not appear in Table 3.
This picture explains everything:
This is my SQLFIDDLE: http://sqlfiddle.com/#!9/5bfc22/2
I did this query but i am not getting what i want:
select * from table1 kio
inner join table2 jio on kio.ORDER_NUMBER = jio.ORDER_NUMBER
where jio.CANCELLED = 0
and not exists (select 1 from table3 gio where jio.ORDER_DETAIL = gio.ORDER_DETAIL)
Also, how can i obtain those orders whose ORDER_DETAILs only appear on TABLE 2 AND those orders whose order_details appear in table 3 with PROCESSED = 1 and APPROVED = 1? All in the same query.