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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:19:24+00:00 2026-06-16T06:19:24+00:00

Query select DISTINCT(a.col1),b.col2 FROM tab1 a RIGHT OUTER JOIN tab2 b ON a.tab1_id=b.tab2_id WHERE

  • 0

Query

select DISTINCT(a.col1),b.col2
FROM tab1 a RIGHT OUTER JOIN  tab2 b
ON a.tab1_id=b.tab2_id
WHERE
a.tab1_id=105

Getting output as

col1           col2
______________________
A               val1
A               val2

I want to concatenate the above result in one value ~ separated

eg. A~val1~val2

Please guide

  • 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-16T06:19:26+00:00Added an answer on June 16, 2026 at 6:19 am

    Your Query:

    SELECT a.col1+'~'+       
           STUFF((
            SELECT '~' + s2.col2
            FROM tab1 s1
            RIGHT OUTER JOIN tab2 s2 ON s1.tab1_id=s2.tab2_id
            WHERE a.col1 = s1.col1
            FOR XML PATH('')
          ), 1, 1, '')  AS columns2
    FROM tab1 a
    RIGHT OUTER JOIN tab2 b ON a.tab1_id=b.tab2_id
    WHERE a.tab1_id=105
    GROUP BY a.col1
    

    Example Query:

    SQLFIDDLEExample

    SELECT
    s.col1+'~'+
    STUFF((
            SELECT '~' + col2
            FROM Table1 s2
            WHERE s2.col1 = s.col1
            FOR XML PATH('')
          ), 1, 1, '')  AS columns2
    FROM Table1 s
    GROUP BY s.col1
    

    Result:

    |    COLUMNS2 |
    ---------------
    | A~val1~val2 |
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an oracle sql query select distinct tab1.col1, tab2.col1 from table1 tab1 join
Given the query: SELECT DISTINCT score.* FROM score LEFT OUTER JOIN tag ON (tag.id_score
Query: SELECT DISTINCT ([Equipment List].ID) AS Expr1, [Job Assignments].Job FROM [Equipment List] LEFT JOIN
I am using this query: SELECT DISTINCT pat.PublicationID FROM dbo.PubAdvTransData AS pat INNER JOIN
I have this query: SELECT DISTINCT IM.EDIFICIOS_ID, TI.TITULAR FROM IMPORTACION IM INNER JOIN I_EDIFICIO
I have the following query: SELECT DISTINCT w.name, count(*) FROM widgets AS w JOIN
i have the following query SELECT DISTINCT dr.Revision FROM tblActionHeader ah INNER JOIN tblActionType
I have a query: SELECT DISTINCT countryName,countrySlug FROM countries AS Country INNER JOIN countries_networks
So I have this query: SELECT DISTINCT(b.friend_id) AS possible_id FROM friend_friends a JOIN friends_friends
I have this query: SELECT DISTINCT(b.friend_id) AS possible_id FROM friends_friends a JOIN friends_friends b

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.