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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:51:55+00:00 2026-06-18T05:51:55+00:00

I have a table with the follwing data Case 1: table1 ————- id type

  • 0

I have a table with the follwing data

Case 1:

table1
-------------
id      type
-------------
1         X
1         Y
2         X
3         Z
3         X
-------------

Now as you see X is common to all the id ,so i need to return X in this case

Case2 :

table1
-------------
id      type
-------------
1         X
1         Y
2         X
2         Y
3         X
3         Y
--------------

In this case both X and Y are common,then i need to return both Xand Y comma seperated (X,y)

Case 3

table1
-------------
id      type
-------------
1         X
1         Y
2         X
2         Y
3         X
3         Y
4         NULL
------------------

If a null came to any of the record , i need to return NULL

Actually ,the data i have shouwn you , is been populated from 3 tables , so i have already written the query for that ,but now i need to compare the groups for the common data within groups ,that is confusing me ,how to compare the groups ?

Note :Here group is based on ID

Any help would be appriciated

  • 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-18T05:51:56+00:00Added an answer on June 18, 2026 at 5:51 am

    you could count the occurances compared to the count of the IDs?

    with data as (select rownum id, 'X' type from dual connect by level <= 3
                  union all
                  select rownum id, 'Y' type from dual connect by level <= 3
                  union all
                  select 3 id, 'Z' type from dual)
    select wm_concat(distinct type)
      from (select type, count(*) over (partition by type) cnt, count(distinct id) over () total_ids
              from data)
     where cnt = total_ids;
    

    in 11g you have LISTAGG instead of WM_CONCAT of course. if for each id, the same type occurs many times, you can change count(*) over (partition by type) to count(distinct id) over (partition by type)

    edit:

    If you had

    3, Z
    3, NULL 
    

    (rather than 4, NULL) and also want to return a NULL rather than a delimited list in that case then you could add a check (with the 4, NULL above it would return a null even on the prior SQL version as the counts would’nt tie up):

           with data as (select rownum id, 'X' type from dual connect by level <= 3
                          union all
                          select rownum id, 'Y' type from dual connect by level <= 3
                          union all
                          select 3 id, 'Z' type from dual)
            select wm_concat(distinct type)
              from (select type, count(*) over (partition by type) cnt, count(distinct id) over 
    
    () total_ids,
                           max(case when type is null then 'Y' else 'N' end) over () has_null_in_set
                      from data)
             where cnt = total_ids
              and has_null_in_set = 'N';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table RDCAlerts with the following data in a column of type
I am using Rails 2.3.8. I have this table Shops with the following data:
I have a table I need to copy my data from (Log), into another
I have a table with some persistent data in it. Now when I query
Let's say I have a table containing following data: | id | t0 |
I have a table with the following data: id | numbers | date ----------------------------------
Lets say i have a table with the following data Customer table: Name amount
Let's say i have a table with the following data: day1 item1 30 day1
Suppose we have the following table data: ID parent stage submitted 1 1 1
I have a MySQL table with the following data (simplified): INSERT INTO `stores` (`storeId`,

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.