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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:36:03+00:00 2026-06-07T19:36:03+00:00

My question is this: Is it possible to output multiple rows when joining from

  • 0

My question is this: Is it possible to output multiple rows when joining from the same table?
With this code for example, I would like it to output 2 rows, one for each table. Instead, what it does is gives me 1 row with all of the data.

SELECT t1.*, t2.* 
FROM table t1
JOIN table t2 
    ON t2.id = t1.oldId
WHERE t1.id = '1'

UPDATE
Well the problem that I have with the UNION/UNION ALL is this: I don’t know what the t1.oldId value is equal to. All I know is the id for t1. I am trying to avoid using 2 queries so is there a way I could do something like this:

SELECT t1.*
FROM table t1
WHERE t1.id = '1'

UNION

SELECT t2.*
FROM table t2
WHERE t2.id = t1.oldId

SAMPLE DATA

messages_users
id    message_id   user_id   box   thread_id   latest_id
--------------------------------------------------------
8     1            1         1     NULL        NULL
9     2            1         2     NULL        16
10    2            65        1     NULL        15
11    3            65        2     2           NULL
12    3            1         1     2           NULL
13    4            1         2     2           NULL
14    4            65        1     2           NULL
15    5            65        2     2           NULL
16    6            1         1     2           NULL

Query:
SELECT mu.id FROM messages_users mu
JOIN messages_users mu2 ON mu2.latest_id IS NOT NULL
WHERE mu.user_id = '1' AND mu2.user_id = '1' AND ((mu.box = '1' 
AND mu.thread_id IS NULL AND mu.latest_id IS NULL) OR mu.id = mu2.latest_id)

This query fixes my problem. But it seems the answer to my question is to not use a JOIN but a UNION.

  • 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-07T19:36:05+00:00Added an answer on June 7, 2026 at 7:36 pm

    You mean one row for t1 and one row from t2?

    You’re looking for UNION, not JOIN.

    select * from table where id = 1
    union
    select * from table where oldid = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, this question with a difference... Is it possible to capture print output from
Following this question, it seems that it is possible to open a file from
Just a follow up question to this one here => link Is it possible
I would like to reuse *.aspx files in multiple ASP.Net MVC projects. Is this
It's possible that this question has already been asked, but I can't seem to
It this possible? How? (Maybe silly question, but I couldn't find answer :( )
This question is a bit open ended as I'm not sure it's possible or
This question was asked quite some time ago, and while it covers possible solutions
Edit (2012-04-12): Since this question was asked it is now possible (as of jQuery
Possible Duplicate: NoClassDefFoundError - Eclipse and Android I'm seeing this question is getting asked

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.