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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:47:53+00:00 2026-06-05T05:47:53+00:00

Using SQL Server Management Studio, I am getting some undesired results (looks like a

  • 0

Using SQL Server Management Studio, I am getting some undesired results (looks like a bug to me..?)

If I use (FIELD rather than field for the other_table):

SELECT * FROM main_table WHERE field IN (SELECT FIELD FROM other_table)

I get all results from main_table.

Using the correct case:

SELECT * FROM main_table WHERE field IN (SELECT field FROM other_table)

I get the expected results where field appears in other.

Running the subquery on it’s own:

SELECT FIELD FROM other_table

I get an invalid column name error.

Surely I should get this error in the first case?

Is this related to collation?
The DB is binary collation.
The server is case insensitive however.
It seems to me like the server component is saying “this code is OK” and not allowing the DB to say the field is the wrong name..?

What are my options for a solution?

  • 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-05T05:47:55+00:00Added an answer on June 5, 2026 at 5:47 am

    Let’s illustrate what is happening using something that doesn’t depend on case sensitivity:

    USE tempdb;
    GO
    
    CREATE TABLE dbo.main_table(column1 INT);
    
    CREATE TABLE dbo.other_table(column2 INT);
    
    INSERT dbo.main_table SELECT 1 UNION ALL SELECT 2;
    INSERT dbo.other_table SELECT 1 UNION ALL SELECT 3;
    
    SELECT column1 FROM dbo.main_table
    WHERE column1 IN (SELECT column1 FROM dbo.other_table);
    

    Results:

    column1
    -------
    1
    2
    

    Why doesn’t that raise an error? SQL Server is looking at your queries and seeing that the column1 inside can’t possibly be in other_table, so it is extrapolating and "using" the column1 that exists in the outer referenced table (just like you could reference a column that only exists in the outer table without a table reference). Think about this variation:

    SELECT [column1] FROM dbo.main_table
    WHERE EXISTS (SELECT [column1] FROM dbo.other_table WHERE [column2] = [column1]);
    

    Results:

    column1
    -------
    1
    

    Again SQL Server knows that column1 in the where clause also doesn’t exist in the locally referenced table, but it tries to find it in the outer scope. So in an imaginary world you might consider the query to actually be saying:

    SELECT m.[column1] FROM dbo.main_table AS m
    WHERE EXISTS (SELECT m.[column1] FROM dbo.other_table AS o WHERE o.[column2] = m.[column1]);
    

    (Which is not how I typed it, but if I do type it that way, it still works.)

    It doesn’t make logical sense in some of the cases but this is the way the query engine does it and the rule has to be applied consistently. In your case (no pun intended), you have an extra complication: case sensitivity. SQL Server didn’t find FIELD in your subquery, but it did find it in the outer query. So a couple of lessons:

    1. Always prefix your column references with the table name or alias (and always prefix your table references with the schema).
    2. Always create and reference your tables, columns and other entities using consistent case. Especially when using a binary or case-sensitive collation.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using SQL Server Management Studio 2005 (SSMS) I can use the import wizard to
I am using SQL Server Management studio and keep getting the same error, and
When scripting a DB using SQL Server Management Studio (SSMS) it generates line like:
Background: I'm using SQL Server Management Studio 2008 and I have a query window
I'm using SQL Server Management Studio 2008 and SQL Server 2008. Currently, I cannot
I have a problem when debugging stored procedure using SQL server Management Studio 2008.
using Visual.Web.Developer.2010.Express; using SQL.Server.Management.Studio.2008.R2; What I'm ultimately trying to do is update a sql
using Visual.Web.Developer.2010.Express; using SQL.Server.Management.Studio.2008.R2; Kinda new at C# here.. I got the first row
I am using SQL Server 2008 management studio to execute the following SQL statements,
I'm using Microsoft SQL Server Management Studio to work with a database. I'm only

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.