Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6005165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:21:46+00:00 2026-05-23T01:21:46+00:00

I have a table that keeps record of targets assigned to different employees for

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:21:47+00:00Added an answer on May 23, 2026 at 1:21 am

    Months with Approved statuses only:

    SELECT DISTINCT month
    FROM myTable a
    WHERE NOT EXISTS
      ( SELECT *
        FROM myTable b
        WHERE a.month = b.month
          AND b.status <> 2
      )
    

    Months without any Pending:

    SELECT DISTINCT month
    FROM myTable a
    WHERE NOT EXISTS
      ( SELECT *
        FROM myTable b
        WHERE a.month = b.month
          AND b.status = 1
      )
    

    There are usually 3 ways to do this kind of problem, (using NOT EXISTS, using NOT IN and using LEFT JOIN with NULL check). 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 1 and 2, this will also work:

    SELECT month
    FROM myTable
    GROUP BY month
    HAVING MIN(status) = 2
    

    Just a final comment/question. Do you only store month in the table, and not year? Because if you also have a year field, the query will not show correct results, once you have data from more than one year in the table.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table that contain date and time field. id|date|time ========= 1|01/01/2001|10:45 2|01/02/2002|11:45 3|01/03/2003|12:45
I have a table that has account numbers in (account_num) and user profiles (profile_id).
I have a table that stores data that has been entered regarding the amount
My database has a table that keeps track of the department and user id.
I have a MySQL table that keeps records of users that answered a question,
I have a table that has a composite key that consists of two int
I have tables Products, Sales and ProductsInStores. ProductsInStores table keeps track of how many
I have a table that keeps track of transactions for various accounts: AccountTransactions AccountTransactionID
I have a table that holds PDF's with meta data, it also has 10
I'm working on an Access database that has a main table that keeps track

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.