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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:07:18+00:00 2026-05-12T21:07:18+00:00

I have a table which contains sales order data (order number, product number, sales

  • 0

I have a table which contains sales order data (order number, product number, sales price, etc.).

However, the table is littered with corrections and various other invalid data. One of the main issues is that corrections were entered by adding a new row with a negative total equal to the amount of a previous order. The sales people were not always thorough and often gave a new order number, or didn’t even list the product number in the correction.

I would like to delete all rows with a negative total, along with their matching (or any other with the same total) positive total row.

My first thought was to simply delete all negative total rows and any positive rows that have the opposite total of them. However, since multiple positive orders exist for many negative orders, this leads to lots of mistakenly deleted positive rows.

How can I delete all rows with a negative total, along with one row for each that has the inverse total?

  • 1 1 Answer
  • 1 View
  • 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-12T21:07:18+00:00Added an answer on May 12, 2026 at 9:07 pm

    depending on how much data there is, I would just do it the brute force way.

    select all the negative total rows into a temp table

    use a cursor to go through each row, then query the database for a single match (using maybe max() on a timestamp, order number, or whatever primary key you might have. Delete that one “matching” row.

    then delete all the negative rows

    No doubt you can use a subquery and do it in one statement, but by the time I figured it out and tested it, I would have the job done using the above 🙂

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

Sidebar

Related Questions

I have a table which contains TV Guide data. In a simplified form, the
I have a table which contains data about which node has been visited. It
I have a table which contains ratings. Included with the rating is data the
I have a table which contains huge data. I want to add hibernate automatic
I have a table which contains data gathered from meteorological observations. The data where
I have table which contains double values stored in mysql database ...I need to
I have one table which contains events and dates, and another which contains the
I have a table which contains a list of Surveys (PK is ID) CREATE
I have a table which contains my ads that can be searched in sql-server-2008.
i have a table which contains a bunch of dynamically created radio button lists,

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.