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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:52:46+00:00 2026-06-04T23:52:46+00:00

How can I delete rows which meet several conditions from a table without primary

  • 0

How can I delete rows which meet several conditions from a table without primary key? (actually the primary key is formed by every column)

After so many tries I have a code that first creates a temporary table where it inserts the rows I want to delete and finally I try to delete the rows from original table which meet the conditions comparing to temporary table.

But it gives me the error about cannot linking the several parts identifier #temp.idCarga

Maybe it’s easy but I have been trying so much time and I cannot focus properly.

CREATE TABLE #TEMP 
(
    CC int,
    idCarga int, 
    Tipo nvarchar(50),
    Importe float,
    Bloque nvarchar(50),
    idsistema int
)

INSERT INTO #TEMP(CC,idCarga,Importe,Bloque,Tipo,IdSistema)
select distinct CI.CC,CI.idCarga,CI.Importe,CI.Bloque,CI.Tipo,CI.idSistema
from CONT_INGRESOS_InformeMayor CI
INNER JOIN 
(
    SELECT idCarga,CC,Bloque,Importe,TIpo
    FROM CONT_INGRESOS_InformeMayor
) CI2 
    ON CI.CC = CI2.CC 
    AND CI.Bloque = CI2.Bloque 
    AND CI.TIpo <> CI2.Tipo
WHERE CI.idCarga = @idCarga 
    AND CI2.idCarga = @idCarga 
    AND CI.Importe = 0

DELETE 
FROM CONT_INGRESOS_InformeMayor 
WHERE idCarga = #temp.idCarga 
    AND tipo = #temp.tipo 
    AND importe = #temp.importe 
    and bloque = #temp.bloque
  • 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-04T23:52:47+00:00Added an answer on June 4, 2026 at 11:52 pm

    You missed a join on your DELETE. Try this:

    DELETE _d
    FROM CONT_INGRESOS_InformeMayor AS _d
    INNER JOIN #temp AS _t
        ON _d.idCarga = _t.idCarga 
        AND _d.tipo = _t.tipo 
        AND _d.importe = _t.importe 
        AND _d.bloque = _t.bloque
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I delete a row from a table which it has been created
I want to delete set of the rows from a table. I can decide
I wanna delete two rows from two tables which are foreign key related how
How can I delete specific DataRows within a loop of a DataTable rows which
i have created a tableview in which we can add and delete rows. On
I'm creating a simple back-end app through which the user can create/update/delete database rows
I need to remove certain rows from a table. Which rows must be deleted
I develop an application in which I need to delete the rows from array
I have form, where some fields are looks like rows, so I can add/delete
I trying to figure out how I can delete from multiple tables in SQL

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.