Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. mysql query

mysql query

Scheduled Pinned Locked Moved Database
databasehelpmysqlquestionlearning
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 13575266
    wrote on last edited by
    #1

    Hi guys, need help again.. newbie here just learning mysql. I have a timesheet table that have a few columns. ie Date, InvNum, Fieldhrs, UserID, ShopHrs. Everyday employees enter their data into database via web page which works great. My problem is this, trying to write a query that checks if every user has entered data for a certain date.. i've tried the following query, but just returns blank not userid ? SELECT UserID FROM timesheet WHERE "2018-04-23" NOT IN ( SELECT Date FROM timesheet ) Any help would be appreciated if someone could point me in right direction.. ie a real newbie.

    J 1 Reply Last reply
    0
    • U User 13575266

      Hi guys, need help again.. newbie here just learning mysql. I have a timesheet table that have a few columns. ie Date, InvNum, Fieldhrs, UserID, ShopHrs. Everyday employees enter their data into database via web page which works great. My problem is this, trying to write a query that checks if every user has entered data for a certain date.. i've tried the following query, but just returns blank not userid ? SELECT UserID FROM timesheet WHERE "2018-04-23" NOT IN ( SELECT Date FROM timesheet ) Any help would be appreciated if someone could point me in right direction.. ie a real newbie.

      J Offline
      J Offline
      Jorgen Andersson
      wrote on last edited by
      #2

      You need a reference for all active users. Assuming you have a Users table you should try something similar to this:

      SELECT u.UserID
      FROM Users u
      LEFT JOIN Timesheet t
      ON t.UserID = u.UserID
      AND t.Date = "2018-04-23"
      WHERE t.UserID IS NULL
      AND u.IsActive = 1

      The existence of IsActive is just an assumption on my part. Add or change conditions as needed. There are other solutions, but this is the probably the best way to do it.

      Wrong is evil and must be defeated. - Jeff Ello

      U 1 Reply Last reply
      0
      • J Jorgen Andersson

        You need a reference for all active users. Assuming you have a Users table you should try something similar to this:

        SELECT u.UserID
        FROM Users u
        LEFT JOIN Timesheet t
        ON t.UserID = u.UserID
        AND t.Date = "2018-04-23"
        WHERE t.UserID IS NULL
        AND u.IsActive = 1

        The existence of IsActive is just an assumption on my part. Add or change conditions as needed. There are other solutions, but this is the probably the best way to do it.

        Wrong is evil and must be defeated. - Jeff Ello

        U Offline
        U Offline
        User 13575266
        wrote on last edited by
        #3

        Thanks. Very helpful. Got it working following your suggestion. Much appreciated.

        J 1 Reply Last reply
        0
        • U User 13575266

          Thanks. Very helpful. Got it working following your suggestion. Much appreciated.

          J Offline
          J Offline
          Jorgen Andersson
          wrote on last edited by
          #4

          You're welcome

          Wrong is evil and must be defeated. - Jeff Ello

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups