I have a table that keeps record of targets assigned to different employees for different products for each month and it has a status field which keeps record of whether assigned target had been approved or not.
status – 1>>Pending, 2>>Approved
Eg:
pdt_id month emp_id status
1 04 1 2
2 04 2 2
3 04 3 1
1 05 1 2
2 05 2 2
3 05 3 2
Now I want to generate a report which shows the only the month for which there are no pending approvals. i.e from the above data the report should only show ’05’ because its the only month in which all the request have been approved
if i provide condition select month where status=’2′ it will fetch both 04 and 05 but i want to fetch only 05 …
Plea
Months with
Approvedstatuses only:Months without any
Pending:There are usually 3 ways to do this kind of problem, (using
NOT EXISTS, usingNOT INand usingLEFT JOINwithNULLcheck). You already have answers for the other 2 ways.In this special case, there’s another (4th) way. If you never plan to add more statuses than the
1and2, this will also work:Just a final comment/question. Do you only store
monthin the table, and notyear? Because if you also have ayearfield, the query will not show correct results, once you have data from more than one year in the table.