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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:53:21+00:00 2026-05-14T20:53:21+00:00

I have a simple join in a query however I need to have a

  • 0

I have a simple join in a query however I need to have a condition on both of the tables “confirmed=’yes'” but if one of the tables doesn’t have any that match the query returns with no rows.

Database:

.----------parties----------.
| id - party_id - confirmed |
|---------------------------|
| 1       1          yes    |
| 1       2          no     |
| 1       3          no     |
+---------------------------+

.-----------events----------.
| id - event_id - confirmed |
|---------------------------|
| 1       1          no     |
+---------------------------+

or

.----------parties----------.
| id - party_id - confirmed |
|---------------------------|
| 1       1          no     |
| 1       2          no     |
| 1       3          no     |
+---------------------------+

.-----------events----------.
| id - event_id - confirmed |
|---------------------------|
| 1       1          yes    |
+---------------------------+

Query:

SELECT p.party_id, e.event_id
FROM parties p
LEFT JOIN events e
ON p.id=e.id
WHERE p.id = '1'
AND p.party_id IN (1,2,3)
AND e.event_id IN (1)
AND p.confirmed='yes'
AND e.confirmed='yes'

It returns nothing but I want it to return party_id 1 with a empty event_id or event_id and a empty party_id. I hope this make sense and I not missing anything, Thanks for your help!

EDIT Added reverse database code that I need to return the event_id and a empty party_id

  • 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-14T20:53:22+00:00Added an answer on May 14, 2026 at 8:53 pm

    Your WHERE conditions filters out all NULLs generated by the LEFT JOIN.

    Move all conditions that involve events into the ON clause:

    SELECT  p.party_id, e.event_id
    FROM    parties p
    LEFT JOIN
            events e
    ON      e.id = p.id
            AND e.event_id IN (1)
            AND e.confirmed = 'yes'
    WHERE   p.id = '1'
            AND p.party_id IN (1, 2, 3)
            AND p.confirmed = 'yes'
    UNION ALL
    SELECT  p.party_id, e.event_id
    FROM    events e
    LEFT JOIN
            parties p
    ON      p.id = e.id
            AND p.party_id IN (1, 2, 3)
            AND p.confirmed = 'yes'
    WHERE   e.event_id IN (1)
            AND e.confirmed = 'yes'
            AND p.id 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 fairly simple one-to-many type join in a MySQL query. In this
I have a simple mySQL problem-- I have two tables, one is a user's
I have 3 tables that I need to join, these join together fine using
I have the following tables and need to do a query Clubs( club_id, name
I have a simple query, select a.*,b.* from myTableA a join myTableB b on
I have this query: SELECT * FROM sample INNER JOIN test ON sample.sample_number =
I have simple database - one table with 6 collumns. 3 of them i
I need to query the MYSQL with some condition, and get five random different
I have a big mysql query which needs to trawl through 4 tables to
This may seem simple, but somehow it isn't. I have a table of historical

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.