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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:01:19+00:00 2026-05-12T00:01:19+00:00

I have 2 tables requests ( ID , company_id , amount ) companies (

  • 0

I have 2 tables

requests (ID, company_id, amount)

companies (ID, name)

with FK constraint (requests.company_id -> companies.id)

requests.company can be NULL

I need to get all requests and replace company_id with appropriated company name or left it blank if no company was specified.

I have next query:

SELECT R.[ID], C.[name] AS [company], R.[amount], ...
FROM [requests] AS R, [companies] AS C, ...
WHERE R.[company_id] = C.[ID]

and it’s working fine until a NULL into company field.

I tried to do next:

SELECT R.[ID], C.[name] AS [company], ...
FROM [requests] AS R, ...
LEFT OUTER JOIN [companies] AS C
ON R.[company_id] = S.ID

But got

The multi-part identifier “R.company_id” could not be bound

And the same errors on fields in ON clause shifting. What am I doing wrong?

  • 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-05-12T00:01:20+00:00Added an answer on May 12, 2026 at 12:01 am

    The code example you showed had ellipses and I believe it is what is in the ellipses that are causing the trouble.

    You have:

    SELECT R.[ID], C.[name] AS [company], ...
    FROM [requests] AS R, ...
    LEFT OUTER JOIN [companies] AS C
    ON R.[company_id] = S.ID
    

    Let’s say that is something like:

    SELECT R.[ID], C.[name] AS [company], X.Field
    FROM [requests] AS R, [eXample] as X 
    LEFT OUTER JOIN [companies] AS C
    ON R.[company_id] = S.ID
    WHERE X.[request_id] = R.ID
    

    In other words the mixing of pre-ANSI 92 inner join syntax with ANSI 92 outer join syntax. Testing on SQL Server 2005, it appears that the alias R for requests is not seen past the comma that separates R from … in your example, and [eXample] as X in mine. The following however did work:

    SELECT R.[ID], C.[name] AS [company], X.Field
    FROM [eXample] as X, [requests] AS R 
    -- Requests and companies on the same side of the comma
    LEFT OUTER JOIN [companies] AS C
    ON R.[company_id] = S.ID
    WHERE X.[request_id] = R.ID
    

    or

    SELECT R.[ID], C.[name] AS [company], X.Field
    FROM [requests] AS R LEFT OUTER JOIN [companies] AS C
        ON R.[company_id] = S.ID, [eXample] as X 
    WHERE X.[request_id] = R.ID
    -- Yuck, I would hate to find this. Not at all sure from reading
    -- the code how it would work.
    

    or my favorite, because I like ANSI 92 join syntax:

    SELECT R.[ID], C.[name] AS [company], X.Field
    FROM [requests] AS R
    INNER JOIN [eXample] as X ON X.[request_id] = R.ID
    LEFT OUTER JOIN [companies] AS C ON R.[company_id] = S.ID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following tables in MySQL server: Companies: - UID (unique) - NAME
So I have two tables: Requests -------- Id RequestSchemeId ReceivedByUserId ForwardedRequests ----------------- Id RequestId
Say I have 2 tables: Blog BlogPosts BlogId BlogPostId Name BlogId Title When I
I need to list only the first five requests for companies from my database.
I work for a hosting company were we often get requests for installs, new
In a Django project as models I have something like that: class Company(models.Model): name
I have 3 tables: Companies, Subcontracts, and CompanyToSubcontract The CompanyToSubcontract table is the guid
i have the following code: (simplified for readability) C# foreach(DataRow dRow in myDS.Tables[0].Rows){ Company
I have two tables. The first table is Requests and it looks like this
I have five tables: User user_id | name -------------------- 0 | Mark 1 |

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.