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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:02:43+00:00 2026-06-15T15:02:43+00:00

select * from TableName FROM THIS: ID Col1 Col2 Col3 Col4 Col5 1 aa

  • 0

select * from TableName

FROM THIS:

ID     Col1    Col2    Col3   Col4    Col5
1       aa      21      ss     m        p
2       aa      21      tt     f        u
3       bb      21      ss     f        d
4       bb      22      ss     m        d 

TO THIS

ID     Col1    Col2    Col3   Col4    Col5
1       aa      21      ss     m        p
2                       tt     f        u
3       bb              ss              d
4               22             m        

i want this Output is it possible ?

don’t want repeat duplicate value if it next to the same

Thanks for your time.

  • 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-15T15:02:44+00:00Added an answer on June 15, 2026 at 3:02 pm

    You can select everything you want to temporary table, clear repeated values and return result set from updated temporary table.

    Query might look like this:

    select 1 as id, 'aa' as col1, '21' as col2,'ss' as col3,'m' as col4,'p' as col5 into #tmp union
    select 2, 'aa','21','tt','f','u' union
    select 3, 'bb','21','ss','f','d' union
    select 4, 'bb','22','ss','m','d' 
    
    
    update t set
        col1 = case when tp.col1 = t.col1 then '' else t.col1 end,
        col2 = case when tp.col2 = t.col2 then '' else t.col2 end,
        col3 = case when tp.col3 = t.col3 then '' else t.col3 end,
        col4 = case when tp.col4 = t.col4 then '' else t.col4 end,
        col5 = case when tp.col5 = t.col5 then '' else t.col5 end
    from #tmp t
    left join (
        select t1.id, max(t2.id) as pid
        from #tmp t1
        join #tmp t2 on t1.id > t2.id
        group by t1.id
    ) p on t.id = p.id
    left join #tmp tp on p.pid = tp.id
    

    Result:

    /*------------------------
    select top 100 * from  #tmp
    ------------------------*/
    id   col1    col2    col3    col4    col5
    1    aa      21      ss      m       p
    2                    tt      f       u
    3    bb              ss              d
    4            22              m    
    

    SQL Fiddle

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an sql query Select * from tablename whose output is col1 col2
I want to get this query at last: select * from tableName where columnName
if i apply a sql query statement to this table select * from context.tablename,
It is possible? DECLARE @vTableName varchar(50) SET @vTableName = (SELECT TableName FROM qms_Types WHERE
Why are these statements valid [am Using SQL2008 R2] Select* FROM TableName --UPDATE: this
This query is working fine: SELECT * FROM tablename where Date >'20091109' and id='11';
Is there a way to do something like this? SELECT * FROM tablename WHERE
select * from tableName where somecode = '$$$$$$$&8Y~$$$$' when I ran this query in
For example this SQL statement returns 1k rows SELECT * FROM tableName WHERE someCondition
I am trying to do this col1 col2 col3 a 1 b a 2

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.