The following SQL Query, when used to create a VIEW is showing the usage of subquery error. This is to fetch the values of a field named CODE from table1 where those values are not present in table2, and also when the Status of those CODE in table2 is not "ASSIGNED" or "SOLD".
SELECT S1.CODE
FROM STOCK S1
LEFT JOIN (
SELECT t1.CODE
FROM STOCK t1
JOIN SALES t2 ON t2.CODE = t1.CODE
WHERE t2.STATUS IN ('Sold', 'Assigned')) S2 ON S2.CODE = S1.CODE
WHERE S2.CODE IS NULL
The SQL query is providing good output, but cannot use this while creating VIEW. Please help me solve this.