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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:22:13+00:00 2026-05-31T13:22:13+00:00

I have rows in a contact details database that look like this: contactID –

  • 0

I have rows in a contact details database that look like this:

contactID - bioID - AddressLine1 - City 
393         1       1 nowhere st   toronto
3921        1       2 somewhere st vancouver
3231        2       1 anywhere rd  barrie
1122        2       2 overthere st halifax      

I am currently inner joining this to a bio table with columns firstname, lastname etc and the results look like this:

bioid    firstname    lastname    addressline1    city
1        some         guy         1 nowhere st    toronto
1        some         guy         2 somewhere st  vancouver
2        that         girl        1 anywhere rd   barrie
2        that         girl        2 overthere st  halifax

So I am basically getting 2 rows for every bio. Is there anyway I can select this all as one row like this:

bioid    firstname    lastname   addressline1x1   cityx1    addressline1x2    cityx2
1        some         guy        1 nowhere st     toronto   2 somewhere st    vancouver
2        that         girl       1 anywhere rd    barrie    2 overthere st    halifax

Any help is appreciated.

Thanks,
Thomas

EDIT:

Thanks a lot to Denis and Justin I was able to solve this problem. However, now I have another.

I would like to actually select the addresses as 1 field such as:

bioid    firstname    lastname    primary address         secondary address
1        some         guy         1 nowhere st, toronto   2 somewhere st, vanvouver
2        that         girl        1 anywhere rd, barrie   2 overthere st, halifax

I know I can do it by concatenating columns like:

cd1.addressline1 + ', ' cd1.city AS 'Primary Address' 

However, some of the fields are empty in the records, for example if there is no secondary address – so how can I make it so the secondary address doesn’t output ‘, ‘? The fields are empty strings, not NULL values.

Thanks again!

EDIT: I’ve got this working using:

STUFF(COALESCE(', ' + NULLIF(C1.[AddressLine1], ''), '') + 
  COALESCE(', ' + NULLIF(C1.[AddressLine2], ''), '') + 
  COALESCE(', ' + NULLIF(C1.[City], ''), '') + 
  COALESCE(', ' + NULLIF(C1.[State], ''), '') + 
  COALESCE(', ' + NULLIF(C1.[Country], ''), '') + 
  COALESCE(', ' + NULLIF(C1.[ZipCode], ''), ''),1, 1, '') AS 'Primary Address'
  • 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-31T13:22:14+00:00Added an answer on May 31, 2026 at 1:22 pm
    ;with cd as(
    select *, rn = dense_rank(partition by bioid order by addressline, city)
    from ContactDetails cd
    )
    select c.bioid, c.firstname, c.lastname, cd1.AddressLine, cd1.City, cd2.AddressLine, cd2.City, cd3.AddressLine, cd3.City
    from Contact c 
    left join cd cd1 on c.bioid = cd1.bioid and cd1.rn = 1
    left join cd cd2 on c.bioid = cd2.bioid and cd2.rn = 2
    left join cd cd3 on c.bioid = cd3.bioid and cd3.rn = 3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have rows like this... | NAME | RED | BLUE | GREEN |
I have 280,000 rows that contain a column called body . This column has
I have a JavaFX 2 table that is displaying contact details for people, lets
I have rows of text data that can vary between 0 and 100, and
I have a datagridview that may or may not have rows selected when the
I have a table that lists people and all their contact info. I want
Given my two db tables aliases and subscriber have entries like this: aliases.username =
I have a query which returns some rows. Its column names are like: Age,
I have an InnoDB table that lists customer orders - this table records the
This is my problem: I have an old database, with no constraints whatsoever. There

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.