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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:47:09+00:00 2026-06-08T04:47:09+00:00

Possible Duplicate: Column does not exist in the IN clause, but SQL runs I

  • 0

Possible Duplicate:
Column does not exist in the IN clause, but SQL runs

I stumbled upon this today while at work today and I was wondering, why is it that the following code does not generate and error?

CREATE TABLE #TableA (ColumnA VARCHAR(25))
CREATE TABLE #TableB (ColumnB VARCHAR(25))

INSERT INTO #TableA (ColumnA) VALUES('1')
INSERT INTO #TableA (ColumnA) VALUES('2')
INSERT INTO #TableA (ColumnA) VALUES('3')

INSERT INTO #TableB (ColumnB) VALUES('1')

SELECT *
FROM #TableA
WHERE ColumnA IN(SELECT ColumnA FROM #TableB)

Output:

ColumnA
1
2
3

ColumnA does not exists on #TableB, how come no error is generated?

@@VERSION tells me I’m running this in:

Microsoft SQL Server 2008 (RTM) - 10.0.1600.22 (X64)   Jul  9 2008 14:17:44   Copyright (c) 1988-2008 Microsoft Corporation  Enterprise Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1) (VM) 
  • 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-08T04:47:12+00:00Added an answer on June 8, 2026 at 4:47 am

    ColumnA in the subquery (SELECT ColumnA FROM #TableB)
    refers to the ColumnA of #TableA which is a valid column in SELECT list.

    Hence there’s no error and you get three rows since you are comparing the #TableA.ColumnA with #TableA.ColumnA

    If you want to verify the above statement replace ColumnA with anything but other than a valid column (e.g ColumnAB) you will get an error.

    If you try this:

    CREATE TABLE #TableA (ColumnA VARCHAR(25))
    CREATE TABLE #TableB (ColumnB VARCHAR(25))
    
    INSERT INTO #TableA (ColumnA) VALUES('1')
    INSERT INTO #TableA (ColumnA) VALUES('2')
    INSERT INTO #TableA (ColumnA) VALUES('3')
    
    INSERT INTO #TableB (ColumnB) VALUES('1')
    
    SELECT *
    FROM #TableA
    WHERE ColumnA IN(SELECT ColumnAB FROM #TableB)
    

    the output will be

    Msg 207, Level 16, State 1, Line 14
    Invalid column name ‘ColumnAB’.

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

Sidebar

Related Questions

Possible Duplicate: jQuery tablesorter - Not sorting column with formatted currency value This http://tablesorter.com/docs/example-meta-parsers.html
Possible Duplicate: SQL Server: Can I Comma Delimit Multiple Rows Into One Column? I
Possible Duplicate: Is there any hash function in PL/SQL? I have a column with
Possible Duplicate: How can I understand nested ?: operators in PHP? Why does this:
Possible Duplicate: What does ||= mean? In this previous question, I asked about an
Possible Duplicate: Was: Not unique table :: Now: #1054 - Unknown column - can't
Possible Duplicate: Splitting one column into two columns in SQL Server CE I am
Possible Duplicate: Difference of create Index by using include column or not using Edit:
Possible Duplicate: SQL Server how to drop identity from a column How I alter
Possible Duplicate: SQL exclude a column using SELECT * [except columnA] FROM tableA? Hi

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.