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

The Archive Base Latest Questions

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

I have a table T1 with the following columns T1 ———- ID | Name

  • 0

I have a table T1 with the following columns

T1
----------
ID | Name
----------
1    Sender1
2    Receiver1
3    Receiver2
4    Sender2

Table T2

T1
---------------------
SenderID | ReceiverID
---------------------
1          2
1          3
4          2

I want to join the two tables in such a way that i want to get the sender and the corresponding receiver grouped. I want the names instead of the IDs. How can this be done in one SQL query

Ex:

Sender                Receiver

Sender1       receiver1
              receiver2

Sender2       receiver1
  • 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-15T12:11:02+00:00Added an answer on May 15, 2026 at 12:11 pm
    select a.name Sender, b.name Receiver
    FROM t2
    INNER JOIN t1 a
    ON t2.SenderID = a.ID
    INNER JOIN t1 b
    ON t2.Receiver = b.ID
    

    Will give you:

    SenderID ReceiverID
    Sender1 Receiver1
    Sender1 Receiver2
    Sender2 Receiver1
    

    If you want to group those results on Sender1, and have the receiver names in one column (separated by \n or space or something), use a group by on a.name. In MySQL for example, there is a group_concat for the b.name‘s.

    The query then becomes

    select a.name Sender, GROUP_CONCAT(b.name SEPARATOR ' ') Receiver
    FROM t2
    INNER JOIN t1 a
    ON t2.SenderID = a.ID
    INNER JOIN t1 b
    ON t2.Receiver = b.ID
    GROUP BY a.name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with the following columns: EntityId, EntityName, EntityProfile, ................. I want
I have a Name table with the columns NameID Name TypeID With the following
I have a table with the following columns: id - INT UNSIGNED AUTO_INCREMENT name
Using SQL Server 2005 I have a table with the following columns id name
I have a table which contains the following columns: UniqueID remote_ip_addr platform I want
I have a table Template with following columns: ID, [Text] Suppose I have two
I have a table with following columns (name : varchar), (mydate : DATE), (endtime
I have a table with the following columns (of urls): [id,url,visited,timestamp] Types:[int,string,int,long] I want
I have a table in the database with the following columns: ID, Name, Txt
I have a table named coords with the following columns |name|lat|lon|und| import sqlite3 database

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.