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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:18:57+00:00 2026-06-17T09:18:57+00:00

I have three tables: Table 1: pid, name, address 1 Dale BLANK Table 2:

  • 0

I have three tables:

Table 1: 
pid, name, address  
1    Dale  BLANK

Table 2: 
pid, moid  
1    12

Table 3: 
moid, address  
12    123 Main   
12    12 South   
12    99 North   

For output I need:

Table 1: 
pid, name, address   
1    Dawn  123 Mian,12 South,99 North

How can I combine multiple addresses in table 3 into one address field in table 1 linking the two tables with information in table 2?

  • 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-17T09:18:58+00:00Added an answer on June 17, 2026 at 9:18 am

    You did not specify what RDBMS you are using. In MySQL you can use GROUP_CONCAT():

    select t1.pid,
      t1.name,
      group_concat(t3.address) Address
    from table1 t1
    left join table2 t2
      on t1.pid = t2.pid
    left join table3 t3
      on t2.moid = t3.moid
    group by t1.pid, t1.name
    

    See SQL Fiddle with Demo

    Edit #1, if you want to UPDATE the table with this result, then the UPDATE statement will look like this:

    update table1 t1
    set address = (SELECT group_concat(t3.address)
                   FROM table2 t2
                   left join table3 t3
                    on t2.moid = t3.moid
                   where t1.pid = t2.pid
                   group by t1.pid, t1.name);
    

    See SQL Fiddle with Demo


    If you are using Oracle 11g+, then you can use the ListAgg() function:

    select t1.pid,
      t1.name,
      listagg(t3.address, ', ') WITHIN GROUP (ORDER BY t1.pid) Address
    from table1 t1
    left join table2 t2
      on t1.pid = t2.pid
    left join table3 t3
      on t2.moid = t3.moid
    group by t1.pid, t1.name
    

    See SQL Fiddle with Demo

    In SQL Server you can use FOR XML PATH to get the result:

    select t1.pid,
      t1.name,
      STUFF((SELECT DISTINCT ', '+ t3.address
             FROM table3 t3
             LEFT JOIN table2 t2
               ON t2.moid = t3.moid
             WHERE t1.pid = t2.pid
             FOR XML PATH('')), 1, 1, '') Address
    from table1 t1
    group by t1.pid, t1.name
    

    See SQL Fiddle with Demo

    All of these produce the result:

    | PID | NAME |                    ADDRESS |
    -------------------------------------------
    |   1 | Dale | 12 South,99 North,123 Main |
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three tables A: A.pID primary key, A.Name nvarchar(250) B: B.pID primary key,
I have three tables like this: Person table: person_id | name | dob --------------------------------
I have three tables, Name - columns Custpackingslipjour(table 1) - (deliverydate, dateclosed,, salesid) Inventrans
Say I have three tables: Fruit (Table 1) ------ Apple Orange Pear Banana Produce
I have three tables of data: table: cars [10,000 rows] table: planes [2,000 rows]
I have three tables Author, Book and AuthorBook. AuthorBook table only contains two foreign
I have three mysql table from same database Db1. Three tables have following columns.
I have three tables Category, Movies and RelCatMov Category-table categoryid, categoryName 1 thriller 2
I have three tables. The designs were like student table create table student (studID
I have three tables Prospect -- holds prospect information id name projectID Sample data

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.