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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:58:03+00:00 2026-06-16T11:58:03+00:00

9amI got help with the query from a previous post but I have a

  • 0

9amI got help with the query from a previous post but I have a new question.
Bear with me in my explanation….

Setup, 2 tables: cal_events which holds dynamic events for a calendar and recurring events that have an update made to them for a single day. Also, cal_events_recurring which holds recurring events.
The query below is an example with dummy data that would be passed by PHP.
I based it off of Dec 15th, so return every event for that day.
The important part is that the recurring event is only returned if it does not have a matching dynamic counterpart. If cal_events, is_overwrite = 1 and its overwrite_id = (the unique id of the 9:00 am cal_events_recurring event, then only return the dynamic table row.
This means, “Hey, I’m an event that occurs every day at 9:00am(example), but look, on Dec 15th the 9:00 recurring event has been updated for that day based on the dynamic table having my unique id = to its overwrite_id so return that one.”

select * from(
    select
        ifnull(ce.time, cer.time) as time,
        ifnull(ce.title, cer.title) as title,
        ce.is_overwrite
    from cal_events_recurring cer
    left join cal_events ce on ce.overwrite_id = cer.id
    where cer.is_daily = 1
    or cer.day_index = 6
    or cer.day_num = 15
    union
    select time as time, title, is_overwrite 
    from cal_events where date = '2012-12-15' 
    and is_active = 1 and is_overwrite = 0) as e order by time asc

This is all well and fine, the data is correct, the problem is the is_active fields.
I’ll go off the 9:00am example again. I created a dynamic event for 9:00am for the 16th which will overwrite the recurring event on the 16th. Now if I later decide I want to revert back to the regular recurring event, I set the is_active field to 0 for the matching dynamic event. The problem is the dynamic event is still returned. If I add and ce.is_active = 0 the event is still returned. How would I write it so that it would still return the recurring event if its dynamic counterpart is not active?

Any other info you need let me know!

EDIT*
output :

time      title 
08:00:00  recurring everyday 8am
09:00:00  dynamic 9am update 

(9am should be the recurring event because the dynamic    is_active = 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-16T11:58:04+00:00Added an answer on June 16, 2026 at 11:58 am

    Put that condition into the ON clause:

    select * from(
        select
            ifnull(ce.time, cer.time) as time,
            ifnull(ce.title, cer.title) as title,
            ce.is_overwrite
        from cal_events_recurring cer
        left join cal_events ce on ce.overwrite_id = cer.id
            and ce.is_overwrite = 1     -- Added this line
        where cer.is_daily = 1
        or cer.day_index = 6
        or cer.day_num = 15
        union
        select time as time, title, is_overwrite 
        from cal_events where date = '2012-12-15' 
        and is_active = 1 and is_overwrite = 0) as e order by time asc
    )
    

    Putting the special condition into the join condition means you still get a left join, but only for rows that should be joined.

    If you put the condition in the where clause, you’ll “break” the intention of the left join and the ifnull(), here’s why:

    Conditions in the ON clause of a join execute as the join is being made, so rows that you don’t want joined don’t get joined and don’t make their values into the ifnull() function.

    It is a common misconception that join conditions can only be “key related”, when in fact they can be anything.

    If you put the condition into the where clause, it is executed after the join is made – where clauses filter results sets, so it’s too late – the ifnull() already has the dynamic table’s data.

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

Sidebar

Related Questions

LATEST Update (Nov 2 2011 9AM) I tried running tnsping from the service and

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.