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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:32:43+00:00 2026-06-08T16:32:43+00:00

mysql> describe holidays; +———+————-+ | Field | Type | +———+————-+ | hid | int(11)

  • 0
mysql> describe holidays;
+---------+-------------+
| Field   | Type        |
+---------+-------------+
| hid     | int(11)     |
| name    | varchar(32) |
| date    | date        |
| enabled | int(1)      |
+---------+-------------+

mysql> 

mysql> describe locations;
+----------+--------------+
| Field    | Type         |
+----------+--------------+
| lid      | int(11)      |
| code     | char(2)      |
| location | varchar(255) |
| enabled  | int(1)       |
+----------+--------------+

mysql> describe holidays_locations;
+-------+---------+
| Field | Type    |
+-------+---------+
| hid   | int(11) |
| lid   | int(11) |
+-------+---------+

mysql> SELECT DISTINCT timesheet.tid, timesheet.uid, timesheet.date, timesheet.location,
IF (timesheet.date = holidays.date AND timesheet.location = holidays.lid, 1, 0) AS is_holiday
FROM (`timesheet`)
LEFT JOIN (SELECT holidays.name AS holiday, locations.location as location, holidays.date AS date, locations.lid AS lid
            FROM holidays_locations
            INNER JOIN holidays ON holidays_locations.hid = holidays.hid
            INNER JOIN locations ON holidays_locations.lid = locations.lid) AS holidays ON holidays.date = timesheet.date
WHERE `uid` =  '12'
AND `timesheet`.`date` >= '2012-05-16'
AND `timesheet`.`date` <= '2012-05-31'
ORDER BY date;

+------+-----+------------+----------+------------+
| tid  | uid | date       | location | is_holiday |
+------+-----+------------+----------+------------+
| 2962 |  12 | 2012-05-18 | 5        |          0 |
| 3163 |  12 | 2012-05-21 | 9        |          1 |
| 3163 |  12 | 2012-05-21 | 9        |          0 |
| 3162 |  12 | 2012-05-21 | 5        |          0 |
+------+-----+------------+----------+------------+

My question is, how do I do this query without the duplicate ‘3163’ entry? The following is what I’m expecting.

+------+-----+------------+----------+------------+
| tid  | uid | date       | location | is_holiday |
+------+-----+------------+----------+------------+
| 2962 |  12 | 2012-05-18 | 5        |          0 |
| 3163 |  12 | 2012-05-21 | 9        |          1 |
| 3162 |  12 | 2012-05-21 | 5        |          0 |
+------+-----+------------+----------+------------+
  • 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-08T16:32:47+00:00Added an answer on June 8, 2026 at 4:32 pm

    You can eliminate the is_holiday = 0 with a MAX() aggregate, grouping by all other columns in your SELECT list.

    SELECT 
      DISTINCT timesheet.tid, 
      timesheet.uid, 
      timesheet.date, 
      timesheet.location,
      /* MAX aggregate will take only the 1, not 0 */
      MAX(IF (timesheet.date = holidays.date AND timesheet.location = holidays.lid, 1, 0)) AS is_holiday
    FROM (`timesheet`)
    LEFT JOIN (SELECT holidays.name AS holiday, locations.location as location, holidays.date AS date, locations.lid AS lid
                FROM holidays_locations
                INNER JOIN holidays ON holidays_locations.hid = holidays.hid
                INNER JOIN locations ON holidays_locations.lid = locations.lid) AS holidays ON holidays.date = timesheet.date
    WHERE `uid` =  '12'
    AND `timesheet`.`date` >= '2012-05-16'
    AND `timesheet`.`date` <= '2012-05-31'
    /* And GROUP BY all other selected columns */
    GROUP BY 
      timesheet.tid, 
      timesheet.uid, 
      timesheet.date, 
      timesheet.location
    ORDER BY date;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 tables: mysql> describe solution_sections; +---------------------+---------------+------+-----+---------+----------------+ | Field | Type | Null
I have 2 tables: mysql> describe solution_sections; +---------------------+---------------+------+-----+---------+----------------+ | Field | Type | Null
I have 4 tables: mysql> describe solution_sections; +---------------------+---------------+------+-----+---------+----------------+ | Field | Type | Null
Given this table : mysql> describe activity; +---------------------------+-------------+------+-----+---------+-------+ | Field | Type | Null
I have this schema: mysql> describe suggested_solution_comments; +-----------------------+----------------+------+-----+---------+----------------+ | Field | Type | Null
I have the following 2 tables.. mysql> describe catalog_category_reference; +----------+---------+------+-----+---------+----------------+ | Field | Type
users table: mysql> describe blog_users; +--------------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key
mysql> describe posts; +-------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default
mysql> describe phppos_sales_suspended; +--------------+--------------+------+-----+-------------------+----------------+ | Field | Type | Null | Key | Default
mysql> describe posts; +----------+---------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default

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.