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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:08:37+00:00 2026-05-27T03:08:37+00:00

I have a table, with rowid, userid, productid, and times. once I ordered the

  • 0

I have a table, with rowid, userid, productid, and times. once I ordered the table by userid and time. It looks like:

u1, t1, p1
u1, t2, p1
u1, t3, p1
u1, t4, p2
u1, t5, p2
u1, t6, p3
u2, t7, p1
u2, t8, p1
u2, t9, p2
u2, t10,p3
 .....

I want to delete those rows whose product id is same as the previous row.
therefore the final table should be :

u1, t1, p1
u1, t4, p2
u1, t6, p3
u2, t7, p1
u2, t9, p2
u2, t10,p3
.....

How can I do this in SQL? Many thanks

  • 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-27T03:08:37+00:00Added an answer on May 27, 2026 at 3:08 am

    Simplified version
    Turns out it is for SQL Server, and you can delete from the CTE directly in SQL Server (as hinted by @Royi Namir in the comments below):

    ;WITH x AS (
        SELECT rowid,
               rownumber() OVER (PARTITION BY user_id,productid ORDER BY times) AS rn
        FROM   tbl
        )
    DELETE FROM x
    WHERE  rn > 1;
    

    Simplified live demo at sqlfiddle.
    Much like this one.

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

Sidebar

Related Questions

I have a table like this: RowID ProductDescription1 1 0296620300-0296620399; 2 0296620400-0296620499;0296620500-0296620599; 3 0296620600-0296620699;0296620700-0296620799;
I have a table like this: RowID; ListDescription1; ListNormalisedDescription1; 1 XXXX YYYY NULL 2
I have a table as follows > RowID SessionID EventID RequestedURL Date > 1
I have table in which I am inserting rows for employee but next time
Lets say I have a table with RowId, and Value: 1 valueA 2 valueB
I inherited a table with the following structure: rowID rn userID Data1 Data2 Data3
I have a table called with thousands of records and would like to implement
I have a table with 4 columns. I want to be able to INSERT
i have a table ---------- User ---------- userID(pk) startdate // update : i am
If have a string passed from a .Net application that looks like the below

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.