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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:52:01+00:00 2026-06-11T04:52:01+00:00

I have more than 1 rows in a table that belong to same ID.

  • 0

I have more than 1 rows in a table that belong to same ID.

I want to select row where more columns contain data .

eg.

My data looks like this

select * from my_table where id=1

PK   Id   Col1   Col2   Col3   Col4   Col5   Col6   Col7   Col8   Col9   Col10
101  1    NULL   NULL   NULL   XX     NULL   NULL   NULL   NULL   NULL   NULL
102  1    NULL   NULL   NULL   XX     YY     NULL   ZZ     NULL   NULL   NULL
103  1    NULL   AA     NULL   NULL   NULL   NULL   NULL   NULL   NULL   NULL
104  1    NULL   NULL   NULL   NULL   NULL   BB     NULL   NULL   NULL   NULL
105  1    NULL   NULL   NULL   NULL   NULL   NULL   NULL   CC     NULL   NULL

I want query which will give me Output like this for id=1 : –

PK   Id   Col1   Col2   Col3   Col4   Col5   Col6   Col7   Col8   Col9   Col10
102  1    NULL   NULL   NULL   XX     YY     NULL   ZZ     NULL   NULL   NULL
  • 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-11T04:52:03+00:00Added an answer on June 11, 2026 at 4:52 am

    Where pk is your primary key…

    select * 
    from YourBadlyStructuredTable
    where pk in (
        select top 1 pk from YourBadlyStructuredTable
        unpivot (col for z in (col1,col2,col3, ...))u
        where id=1
        group by pk
        order by COUNT(*) desc
    )
    

    If you can’t specify your column names…

    select 
        top 1 
        HorribleTable.* 
    from
    (
        select
            xmldata.value('(/x2/@PK)[1]','int') as PK1,
            xmldata.value('(/x2/@Id)[1]','int') as ID1,
            xmldata.value('count(/x2/@*)','int') as cnt
            from
            (
        select      
            t.x.query('.') as xmldata               
        from
            (   select convert(xml,(select * from HorribleTable for xml raw('x2'))) as x1) v
                cross apply
            v.x1.nodes('/x2') t(x)
        ) v
    ) v
        inner join HorribleTable on v.PK1 = HorribleTable.pk
    where ID1 = 1 
    order by cnt desc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MyISAM table with more than 10^7 rows. When adding data to
I have just create a large table with more than 30 rows of data,
I have to delete about 10K rows from a table that has more than
I need to select a row from table that has more than 5 millions
I have table that contains more than 12 millions of rows. I need to
I have more than 50,000 rows of data in Excel that look like this:
I have a very long table (more than 1000 rows) that takes a long
I have a table that contains more than 15k rows of records. I'm pulling
I have a table with more than 9 rows. If I do this :
I'm looking to grab a group of tables that have more than X rows

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.