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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:03:58+00:00 2026-06-07T18:03:58+00:00

I’m working on a little project, is sort like a agenda for technicians, each

  • 0

I’m working on a little project, is sort like a agenda for technicians, each technician is assigned on a daily agenda.

I’m looking for a query that shows me only the technicians that hasn’t been assigned on a day in a branch (the company has two branches: East and West)

The query I’ve tried is:

SELECT *
FROM technicians
WHERE id_tech NOT
IN (    
     SELECT id_tech
     FROM hours
   )
AND branch = 'West'

This query returns me what I want, but I don’t know how to filter this with a date, I’ve tried many queries, and return me all the colums with duplicate results.

My tables are, the hours table where each tech has a task:

CREATE TABLE IF NOT EXISTS `hours` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_tech` int(11) NOT NULL,
  `9_30` varchar(140) DEFAULT NULL,
  `10_30` varchar(50) DEFAULT NULL,
  `11_30` varchar(50) DEFAULT NULL,
  `12_30` varchar(50) DEFAULT NULL,
  `1_30` varchar(50) DEFAULT NULL,
  `2_30` varchar(50) DEFAULT NULL,
  `3_30` varchar(50) DEFAULT NULL,
  `4_30` varchar(50) DEFAULT NULL,
  `5_30` varchar(50) DEFAULT NULL,
  `6_30` varchar(50) DEFAULT NULL,
  `comments` varchar(50) DEFAULT NULL,
  `date` text NOT NULL,
  PRIMARY KEY (`id`)
) TYPE=MyISAM  ROW_FORMAT=DYNAMIC;

INSERT INTO `hours` (`id`, `id_tech`, `9_30`, `10_30`, `11_30`, `12_30`, `1_30`, `2_30`, `3_30`, `4_30`, `5_30`, `6_30`, `comments`, `date`) VALUES
(1, 1, 'Router with problems, Customer ID 111', 'Router with problems, Customer ID 111', 'Router with problems, Customer ID 111', 'Router with problems, Customer ID 111', 'Router with problems, Customer ID 111', 'Desktop with problems, Customer ID 121', NULL, NULL, NULL, 'Network problems, Customer ID 121', 'Router with problems, Customer ID 111', '16-07-2012'),
(3, 3, 'Network with problems, Customer ID 111', 'Network with problems, Customer ID 111', NULL, NULL, NULL, NULL, NULL, NULL, 'Network with problems, Customer ID 111', '', 'Didn''t came to work today', '16-07-2012');

And the technicians table:

CREATE TABLE IF NOT EXISTS `technicians` (
  `id_tech` int(11) NOT NULL,
  `name` varchar(50) COLLATE utf8_spanish_ci NOT NULL,
  `branch` varchar(50) COLLATE utf8_spanish_ci NOT NULL,
  PRIMARY KEY (`id_tech`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci ROW_FORMAT=DYNAMIC;


INSERT INTO `technicians` (`id_tech`, `name`, `branch`) VALUES
(1, 'Peter', 'East'),
(2, 'Juan', 'East'),
(3, 'Rick', 'West'),
(4, 'Mario', 'West');
  • 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-07T18:04:00+00:00Added an answer on June 7, 2026 at 6:04 pm

    Put the date comparison as one of the conditional checks in the LEFT JOIN:

    SELECT a.*
    FROM technicians a
    LEFT JOIN hours b ON 
              a.id_tech = b.id_tech AND 
              STR_TO_DATE(b.date, '%d-%m-%Y') = CURDATE()
    WHERE a.branch = 'West' AND b.id_tech IS NULL
    

    ^ This will get all technicians who do not have an assignment for the current day.

    -- Get all West branch technicians who have not been assigned within past week
    
    SELECT a.*
    FROM technicians a
    LEFT JOIN hours b ON 
              a.id_tech = b.id_tech AND 
              STR_TO_DATE(b.date, '%d-%m-%Y') >= CURDATE() - INTERVAL 1 WEEK
    WHERE a.branch = 'West' AND b.id_tech IS NULL
    

    If you want to compare on a specific day in the past:

    -- Get all West branch technicians who have not been assigned on a particular
    -- day in the past:
    
    SELECT a.*
    FROM technicians a
    LEFT JOIN hours b ON 
              a.id_tech = b.id_tech AND 
              STR_TO_DATE(b.date, '%d-%m-%Y') = CAST('2012-06-14' AS DATE)
    WHERE a.branch = 'West' AND b.id_tech IS NULL
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has

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.