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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:33:42+00:00 2026-05-30T06:33:42+00:00

I have read and learned a lot here, got a lot of problems solved

  • 0

I have read and learned a lot here, got a lot of problems solved without asking anything so far, but I couldn’t cope with this one.

I have three tables:

-programs
 ->ProgramID (Primary Unique)
 ->ProgramName
 ->AuditID

-audits
 ->AuditID (Primary Unique)
 ->VenueName
 ->Address

-events
 ->EventID (Primary Unique)
 ->EventDate
 ->ProgramID
 ->AuditID

Events are instances of those programs that are on stage that day. Multiple instances of one program might be performed on one day, or none if it’s not played. This is basically a temporary table, repopulated daily. Tickets can be bought from programs that are played on said day.

Audits are the actual stages where the plays are performed. A theatre can have several stages.

Programs are plays for theatres that are on their repertoire for years. The last stage where it was is performed is stored for when someone retrieves the information of a program that is not played on the actual day the stage can still be linked.

I am using this query now:

SELECT
    programs.ProgramID,
    programs.ProgramName,
    programs.AuditID,
    events.EventID,
    events.EventDate,
    audits.VenueName,
    audits.Address
FROM programs
LEFT JOIN events
ON programs.ProgramID = events.ProgramID
JOIN audits
ON programs.AuditID = audits.AuditID
WHERE programs.ProgramID = :ProgramID
  • If there is no event of that program the LEFT JOIN gives me information about the program and the audit leaving the event info blank. Good.
  • Also okay when the event is at the same audit where it was played last time. Great.
  • The problem is if it’s played in a different audit, because the JOIN for the audits table is made based on programs.AuditID key, which is obsolete now.

What I would need is a conditional JOIN, so that when the events.AuditID is not null, the audits table is joined using events.AuditID instead of programs.AuditID.

Thanks in advance!

  • 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-05-30T06:33:44+00:00Added an answer on May 30, 2026 at 6:33 am

    I believe you should be able to JOIN using IFNULL(events.AuditID, programs.AuditID) to solve this problem…

    SELECT
        programs.ProgramID,
        programs.ProgramName,
        programs.AuditID,
        events.EventID,
        events.EventDate,
        audits.VenueName,
        audits.Address
    FROM programs
    LEFT JOIN events
    ON programs.ProgramID = events.ProgramID
    JOIN audits
    ON IFNULL(events.AuditID, programs.AuditID) = audits.AuditID
    WHERE programs.ProgramID = :ProgramID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read a lot about mocking, particularly using Rhino Mocks and have learned
I have read some posts on here about not mixing parameters when passing into
I have read that you can do it, but would this really improve performance
I have read this question but it's not quite what I was looking for.
I have read in a lot of places that assembly language is not usually
I have read several post on both matters but I haven't seen anyone comparing
Thanks to the help of some most excellent members on here I have learned
I have read a lot that LISP can redefine syntax on the fly, presumably
I hope this hasn't already been answered, but I feel like I have read
I have read a lot of books about Microsoft Dot Net and I have

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.