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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:53:44+00:00 2026-06-18T05:53:44+00:00

Schema: create table TableA (A1 int) create table TableB (B1 int, B2 int) create

  • 0

Schema:

create table TableA (A1 int)
create table TableB (B1 int, B2 int)
create table TableC (C1 int)

Problematic query:

SELECT * 
FROM TableA a
INNER JOIN TableB b ON b.B1=a.A1
INNER JOIN (SELECT TOP 1 * 
            FROM TableC c
            WHERE c.C1=b.B1 ORDER BY c.C1) d ON d.C2=b.B2
INNER JOIN OtherTable ON OtherTable.Foo=d.C1

Building this schema and running the query in SQLFiddle under SQL Server 2008 results in:

The multi-part identifier "b.B1" could not be bound.: SELECT * FROM TableA a INNER JOIN TableB b ON b.B1=a.A1 INNER JOIN (SELECT TOP 1 * FROM TableC c WHERE c.C1=b.B1 ORDER BY c.C1) d ON d.C2=b.B2

Using CROSS APPLY instead of INNER JOIN for the subquery fixes the issue

What’s the problem?

Edit: I added “TOP 1” that was part of the real query and it’s a relevant part of the problem.

Edit2: Further information about the problem.

  • 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-18T05:53:45+00:00Added an answer on June 18, 2026 at 5:53 am

    you can’t reference from JOIN clause to another part of JOIN.

    Use this instead.

    SELECT * 
    FROM TableA a
    INNER JOIN TableB b
        ON b.B1=a.A1
    INNER JOIN TableC c
        ON d.C2=b.B2
          AND c.C1=b.B1
    

    EDITED

    SELECT * 
    FROM TableA a
    INNER JOIN TableB b ON b.B1=a.A1
    WHERE b.B2 = (SELECT TOP 1 c.C2 
                   FROM TableC c
                   WHERE c.C1=b.B1 ORDER BY c.C1)
    

    For further use of TableC in JOIN-s you can use this.

    SELECT * 
    FROM TableA a
        INNER JOIN TableB b
            ON b.B1=a.A1
        INNER JOIN
           (
               SELECT
                   ROW_NUMBER() OVER (PARTITION BY C1 ORDER BY C2) RN,
                   C2
                   --, other columns fromTableC if needed
               FROM TableC
           ) CC
         ON b.B2 = CC.C2
           AND CC.RN = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following schema: create table TableA (A1 int) create table TableB (B1 int,
Here's my database schema: create table Post ( PostId int primary key identity, ImageUrl
Consider the following schema: create table A ( id int primary id ) create
I have following table schema - CREATE TABLE [dbo].[TEST_TABLE] ( [TEST_TABLE_ID] [int] IDENTITY(1,1) NOT
CREATE TABLE [schema].[table] ( [column1] int IDENTITY NOT NULL, [column2] int NULL, [column3] int
Below is my table Schema: CREATE TABLE [dbo].[Sample]( [BoardId] [int] IDENTITY(1,1) NOT NULL, [UserCode]
I have SQL Server tables as follows: create table TableA ( id int primary
Here is a table schema: CREATE TABLE `tag` ( `id` int(10) unsigned NOT NULL
I currently have this schema: CREATE TABLE `users` ( `users_id` int(11) NOT NULL AUTO_INCREMENT,
I have 3 tables with the following schema: CREATE TABLE `devices` ( `device_id` int(11)

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.