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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:26:51+00:00 2026-06-17T11:26:51+00:00

There seem to be a few questions like this, but none exactly the same,

  • 0

There seem to be a few questions like this, but none exactly the same, so here goes:

I need to find a way to delete a row in one table where there is a row in another table that has two of its fields equal to two fields from the original table. (In the following example, this will read:
I need to find a way to delete a row in @All that has @All.Stall = @Grouped.Stall and @All.Fruit = @Grouped.Fruit)

For example:

@All: Table to have rows deleted:

Stall       Fruit
-------------------
John        Apples
John        Pears
John        Pineapple
Mary        Apples
Mary        Apples
Mary        Pears
Mary        Pineapple

@Grouped: Table to get rows to delete from:

Stall       Fruit
-------------------
Mary        Apples

The resultant table should look like this:

Stall       Fruit
-------------------
John        Apples
John        Pears
John        Pineapple
Mary        Pears
Mary        Pineapple

Note that the two rows that contain: Mary | Apples are gone.

For the life of me, I cannot figure out how to do this, and can only get it to remove all three rows that contain Apples and not leave the one John | Apples.

Here are the queries to create the two temporary tables, if anyone is able to help:

@All – Table to have rows deleted

@Grouped – Table with fields to look-up to delete from @All

DECLARE @All TABLE(
    Stall varchar(10),
    Fruit varchar(10),
    StallFruitID int
)

DECLARE @Grouped TABLE(
    Stall varchar(10),
    Fruit varchar(10)
)

INSERT INTO @All (Stall,Fruit,StallFruitID) VALUES('John','Apples',1)
INSERT INTO @All (Stall,Fruit,StallFruitID) VALUES('John','Pears',1)
INSERT INTO @All (Stall,Fruit,StallFruitID) VALUES('John','Pineapple',1)
INSERT INTO @All (Stall,Fruit,StallFruitID) VALUES('Mary','Apples',1)
INSERT INTO @All (Stall,Fruit,StallFruitID) VALUES('Mary','Apples',2)
INSERT INTO @All (Stall,Fruit,StallFruitID) VALUES('Mary','Pears',1)
INSERT INTO @All (Stall,Fruit,StallFruitID) VALUES('Mary','Pineapple',1)

INSERT INTO @Grouped (Stall,Fruit) VALUES('Mary','Apples')
  • 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-17T11:26:52+00:00Added an answer on June 17, 2026 at 11:26 am
    DELETE  a
    FROM    table1 a
            INNER JOIN table2 b
                ON  a.Stall = b.Stall AND
                    a.Fruit = b.Fruit
    
    • SQLFiddle Demo
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know there are already a few questions like this but I can't seem
There a few similar questions here on SO, but none seem to quite answer
There seem to be many questions asked about this subject here on stackoverflow, but
I know this questions has been asked a few times here. But these seem
There are a few questions that approach an answer to this question, but none
I've seen a few questions out there regarding this but I can't seem to
I know there are a few questions on this already but I can't seem
There are quite a few other questions similiar to this but none of them
I know there are multiple questions on here related to the same issue but
First off, I'm aware that there are many questions related to this, but none

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.