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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:58:43+00:00 2026-05-26T03:58:43+00:00

I’m trying to get a list of IDs from three tables. table_one ——— |

  • 0

I’m trying to get a list of IDs from three tables.

table_one
---------
| id | other_data |

table_two
---------
| this_id | user_id | time_qual |

table_three
---------
| this_id | second_qual |

I want to get a list back of table_one ids with the following qualifications:

  1. the id is also found in table_three‘s this_id
  2. second_qual in table_three is equal to 1
  3. this_id in table_two equals table_one‘s id AND in the same row, table_two‘s user_id equals the php variable $user_id AND time_qual in that row equals 1.
  4. but also include ids that qualify for #1 and #2, and not #3 if table_one‘s id and the php variable $user_id isn’t found on the same row of table_two

This is my attempt:

        SELECT tb1.id FROM table_one tb1
          INNER JOIN table_two tb2
          INNER JOIN table_three tb3
          WHERE tb2.this_id = tb1.id
           AND tb3.this_id = tb1.id
           AND tb3.second_qual = 1
           AND ((tb2.user_id = $user_id AND tb2.time_qual = 1)
              OR ($user_id NOT IN (SELECT user_id FROM table_two)))
           GROUP BY tb1.id

I’m guessing there should be a UNION in there and that tb2.this_id = tb1.id eliminates the results I want from #4, but I’m not sure what to do.

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-26T03:58:44+00:00Added an answer on May 26, 2026 at 3:58 am

    To the best of my ability to parse your requirements, I think this is the answer. Let me know if it misses and I can amend:

    SELECT t1.id
    FROM table_three t3 
    RIGHT JOIN table_one t1 
      ON t1.id=t3.this_id 
    LEFT JOIN table_two t2 
      ON t1.id=t2.this_id 
    WHERE (t3.this_id IS NOT NULL AND t3.second_qual=1) 
      AND ((t2.this_id IS NOT NULL AND t2.user_id=1 AND t2.time_qual=1) 
        OR t2.this_id IS NULL);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string

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.