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 8077255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:26:06+00:00 2026-06-05T15:26:06+00:00

I am facing a situation and need help. I have two tables: user: user_id

  • 0

I am facing a situation and need help. I have two tables:

user:

  • user_id, fname, lname, email.

user_timesheet:

  • time_id, user_id, month, state, date.

Users are to add time to user_time table with the state as = ‘no’ and at the end of the month they submit that time which change the state = ‘yes’ assuming the month is JUNE
I want to write a query that will bring all users who did not add time at all and users who have added time but has not submit for JUNE.

This is my query.

SELECT user_timesheet.time_id, user_timesheet.user_id, 
    user_timesheet.month, user_timesheet.`state`, 
    `user`.user_id, `user`.fname, `user`.lname,  
    `user`.email
FROM user LEFT JOIN  
     user_timesheet ON user.user_id=user_timesheet.user_id
WHERE (
    user_timesheet.state = 'no' OR 
    user_timesheet.state IS NULL) 
AND (
    user_timesheet.month = 'june' OR 
    user_timesheet.month IS NULL)
GROUP BY user.user_id

The result bring all users who have added time in june but have submitted it and also the users who have NEVER ADDED TIME to the system since they join. It however does not bring users who have either added time or submitted time in the previous month but has not added time at all for june.

  • 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-06-05T15:26:07+00:00Added an answer on June 5, 2026 at 3:26 pm

    Instead of (a = x or a is null) in where clause put your filter in ON clause. This will remove non-matching records but preserve nature of left join.

    To treat ‘no’ status as non existant row filter it out of left join:

    SELECT user_timesheet.time_id, user_timesheet.user_id, 
           user_timesheet.month, user_timesheet.`state`, 
           `user`.user_id, `user`.fname, `user`.lname,  
           `user`.email
      FROM user 
      LEFT JOIN user_timesheet
      -- Eliminate users who have submitted 'no'
      -- For June
        ON user.user_id=user_timesheet.user_id
        -- Turn 'no' status into null record
       AND user_timesheet.state <> 'no'
       AND user_timesheet.month = 'june'
      -- If there is no row in user_timesheet
      -- It means that
      --    a) There was not any
      --    b) There was a 'no' status
     WHERE user_timesheet.user_id is null
     GROUP BY user.user_id
    

    Note: I don’t know what is comment marker in MySql. It is — in Sql Server, so delete this lines before you try the query.

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

Sidebar

Related Questions

Here is the situation that I'm facing: I have two tables A and B.
I am facing a situation where I need to process an incoming email which
I have a situation where i need to create a left panel. My manager
I'm facing a situation where I have dependent objects and I would like to
I am facing a situation that I have problem understanding... I am writing a
I am new to VB.net and facing a strange situation. I have a structure
I'm facing this situation where I have an ID which comes from a database
I am facing a situation in which I have a ListView item. When I
I am facing a weird behavior and I need some help.. I encounter a
This is the situation I am facing. I have developed a web application that

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.