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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:22:56+00:00 2026-06-04T12:22:56+00:00

I’m trying to generate a report base on pre defined dates(cutoff dates). I have

  • 0

I’m trying to generate a report base on pre defined dates(cutoff dates). I have two tables, the in and out and overtime table.

IN and OUT table

in and out table

Overtime Table

overtime table

Expected Result

enter image description here

Using UNION, it doubles the dates, but that can be solve supposedly by group by, but group seems not to work in UNION.

And the tricky part is to show the BLANK 6-Jan and 5-Jan. I need to show this coz its a timesheet report.

Any help or clue will be greatly appreciated

CODE:

SELECT emp_id,in,out,null 
FROM normal 
WHERE date >= '1-Jan' 
  AND date <= '10-Jan' 
  AND emp_id = '10001'
UNION
SELECT emp_id,null,null,minutes 
FROM overtime 
WHERE date >= '1-Jan' 
  AND date <= '10-Jan' 
  AND emp_id = '10001'
  • 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-04T12:22:58+00:00Added an answer on June 4, 2026 at 12:22 pm

    Something like this should do what you want(if i weel understood the question) :

    SELECT n.date, n.emp_id, n.in, n.out, o.minutes
    FROM normal n 
    JOIN overtime o USING(emp_id)
    WHERE n.date BETWEEN '2012-01-01' AND '2012-01-10'
    

    Keep in mind that if you want to show even the dates with no matches, you have to create a table with the list of this dates :

    dates

    +------------+
    | timestamp  |
    |------------+
    | 2012-01-01 |
    | 2012-01-02 |
    | ....       |
    

    Then you can change the query in this way to get the result set you want :

    SELECT d.timestamp AS date, b.emp_id, b.in, b.out, b.minutes
    FROM dates d
    LEFT JOIN 
    (SELECT n.date AS timestamp, n.emp_id AS emp_id, n.in AS in, n.out AS out, o.minutes AS minutes
     FROM normal n 
     JOIN overtime o USING(emp_id)
     ) b 
     USING(timestamp)
     WHERE d.timestamp BETWEEN '2012-01-01' AND '2012-01-10'
    

    If you want to avoid the dates table you can try with this more complex query, should give you the same result, without the needs of a third table that store the range of dates :

    SELECT d.timestamp AS date, b.emp_id, b.in, b.out, b.minutes
    FROM ( 
    SELECT '2012-01-01' + INTERVAL a + b DAY AS timestamp
    FROM
    (SELECT 0 a UNION SELECT 1 a UNION SELECT 2 UNION SELECT 3
    UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7
    UNION SELECT 8 UNION SELECT 9 ) d,
    (SELECT 0 b UNION SELECT 10 UNION SELECT 20 
    UNION SELECT 30 UNION SELECT 40) m
    WHERE '2012-01-01' + INTERVAL a + b DAY  <  '2012-01-11'
    ORDER BY a + b
    ) d
    LEFT JOIN 
    (SELECT n.date AS timestamp, n.emp_id AS emp_id, n.in AS in, n.out AS out, o.minutes AS minutes
     FROM normal n 
     JOIN overtime o USING(emp_id)
     ) b 
     USING(timestamp)
    
    • 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&#8217;Everest What PHP function
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.