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

  • Home
  • SEARCH
  • 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 213211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:15:26+00:00 2026-05-11T18:15:26+00:00

I have 2 tables set up like this (irrelevant rows omitted): > product –

  • 0

I have 2 tables set up like this (irrelevant rows omitted):

> product
  - id
  - user_id

> thread
  - id
  - prod_id
  - user_id
  - due_date

now I want to create a query that picks all rows from thread table that either:

  1. have a thread.user_id of (for example) “5”
  2. have a prod_id where the product.user_id is “5”

I am assuming there is a way to do this, something like …

SELECT 
    thread.due_date 
FROM
    product, thread 
WHERE 
    thread.user_id='5' 
OR 
    // not sure how to finish it

Up to this point, I would just use PHP to do this, but would really like to kick up my SQL knowledge a notch and get this working via SQL if possible.

Thanks –

  • 1 1 Answer
  • 2 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-11T18:15:27+00:00Added an answer on May 11, 2026 at 6:15 pm

    You should be able to use an outer join to do this:

    SELECT thread.* FROM thread 
    LEFT OUTER JOIN product
    ON thread.prod_id = product.id
    WHERE thread.user_id = 5 OR product.user_id = 5
    

    A problem you might find is that you could get duplicate threads if a thread has a user id 5 but also a product with user id 5. Not sure if that will be an issue in your case though. You may be able to use SELECT DISTINCT to remove these (thanks Alex Martelli)

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

Sidebar

Related Questions

I have a set of tables in Oracle and I would like to identify
I have a set of tables with children of children, like so: Clients (PK
I have tables like this: Table1 Table2 name1 | link_id name2 | link_id text
We have an Access DB which has a set of local tables and input
This is what I'm trying to do: I have 2 tables... CREATE TABLE `parent`
I have two tables, products and category. A product can be in multiple categories.
I have three tables I'd like to join in a way that produces all
Let's say I have 2 tables. TableA only has one column and looks like
I have a pretty standard table set-up in a current application using the .NET
I have one table that saves comments for a varied set of content types.

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.