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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:38:29+00:00 2026-05-30T02:38:29+00:00

I have table X, and each record in X has many records in Y.

  • 0

I have table X, and each record in X has many records in Y.
I want a simple SQL which brings just the records from X which has the same set of records from Y.
Each group of records from X I want it to be distinguished from other group (which has another set of records from Y) with some value.

Example:

1 - 5
  - 6
2 - 3
3 - 5
  - 6
4 - 3
5 - 7

I want it back as:

1 - a
3 - a
2 - b
4 - b
5 - c
  • 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-30T02:38:31+00:00Added an answer on May 30, 2026 at 2:38 am

    This looks like a job for wm_concat or stragg, which will give you your unique values without you having to transliterate them to something.

    select x.id, stragg(x.value)
      from table_x x
     group by x.id
    

    And with your comment you can guarantee order in a sub-query:

    select id, substr(stragg(value),1,10)
      from ( select id, value
               from table_x
              order by id, value )
     group by id
    

    The only problem is your values won’t be “pretty” they’ll be a concatenation of all the possible values you have in table_x

    SQL> create table table_x ( id number, value number);
    
    Table created.
    
    SQL> insert into table_x values (1,5);
    
    1 row created.
    
    SQL> insert into table_x values (1,6);
    
    1 row created.
    
    SQL> insert into table_x values (2,3);
    
    1 row created.
    
    SQL> insert into table_x values (3,6);
    
    1 row created.
    
    SQL> insert into table_x values (3,5);
    
    1 row created.
    
    SQL> insert into table_x values (4,3);
    
    1 row created.
    
    SQL> insert into table_x values (5,7);
    
    1 row created.
    
    SQL> commit;
    
    Commit complete.
    
    SQL>
    SQL> select id, substr(stragg(value),1,10)
      2    from ( select id, value
      3             from table_x
      4            order by id, value )
      5   group by id
      6         ;
    
            ID STRAGG(VALUE)
    ---------- ----------
             1 5;6
             2 3
             3 5;6
             4 3
             5 7
    
    SQL>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a recursive table in which each record has an ID and a
I have the correlated subquery below. Each id (147,148,149) in table1 has many records
Background I have a dimension table that has a single record for each day.
I have table with date/time column and person column. Each person has multiple records
I have a table that has a one to many relationship with itself. Each
I have a table with three numbers in each record, a minimum, a maximum,
I have a table with two child tables. For each record in the parent
In each table have many number of rows with amount. Like this i have
I have a table where each row has a description field as well as
I have two SAS data tables. The first has many millions of records, and

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.