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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:55:18+00:00 2026-06-10T23:55:18+00:00

Using SQL Server 2008 R2 (Version 10.50.4000.0): I have two tables. I want to

  • 0

Using SQL Server 2008 R2 (Version 10.50.4000.0):

I have two tables. I want to delete data in one table where an ID exists in another table. Simple enough. However, due to a mistake in typing, I found what appears to be a parser bug.

In the script below, [SomeID] is a column in Table1 but does not actually exist in Table2

Delete from Table1 where [SomeID] in (Select [SomeID] from Table2)

If you run the subquery "Select [SomeID] from Table2, you get an appropriate error message stating that the column does not exist.

If you run the whole delete query though, it runs without error, and deletes everything in table1

It seems that the parser should have caught that the column did not exist in table 2. I know you can use columns from outside the sub-query, and I realize that the parser was assuming that I meant to use a column from table1, but since I had not specified any columns from table2, the parser should have, in my opinion, been smart enough to know there was something wrong. Fortunately, we were in a test environment when this happened. 🙂

Thanks,
Tony

  • 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-10T23:55:19+00:00Added an answer on June 10, 2026 at 11:55 pm

    It’s not an error
    The engine will do what you put in the query.

    when you use In clause, it will compare for each row, the field SomeId, with the result in the In

    For example, you could do this

    Delete from Table1 where [SomeID] in (Select [SomeID] from Table2 where IdTable2 = SomeId)
    

    So, you could return anything in the select, as a constant, as an Id in the table2, a sum of both, or, like this case, the ID in the first Table.

    In this case, when execute the subquery, as doesn’t have a where clause, the subquery will always return a result (unless got no rows), because it doesn’t have a filter, but what will show ? You’re specifying a field in the parent-query, and you’re able to show it, so it will return it.
    Of corse, as you’re comparing with In, so is deleting all in table1, right ?

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

Sidebar

Related Questions

We are using SQL Server 2008 Enterprise version. We have a large table FooTable
I am using SQL Server 2008 Enterprise version. I want to know if I
I'm using SQL Server 2008. I have a table with x amount of rows.
Ok I'm using SQL Server 2008 and have a table field of type VARCHAR(MAX)
I have a SQL Server 2008 DB with many tables filled with data and
Using SQL Server 2008. I have multiple Locations which each contain multiple Departments which
Using SQL Server 2008, is there a way to allow inserts to a table
I am using SQL Server 2008 R2, I have a script to update the
Hi i am using SQL Server 2008 R2, i have lots of procedures in
I am using SQL Server 2008 express and i want to import .mdf and

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.