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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:26:28+00:00 2026-06-05T22:26:28+00:00

I need help with how to write a SQL Server 2005 query to handle

  • 0

I need help with how to write a SQL Server 2005 query to handle joining multiple subtables. Here is my scenario:

Tables:

Customers

  • Customer_PK

Orders

  • Order_PK
  • OrdersTypeA_FK
  • OrdersTypeB_FK
  • OrdersTypeC_FK
  • Customer_FK

OrdersTypeA

  • OrdersTypeA_PK
  • Shipper_FK

OrdersTypeB

  • OrdersTypeB_PK
  • Shipper_FK

OrdersTypeC

  • OrdersTypeC_PK
  • Shipper_FK

Shippers

  • Shipper_PK
  • ShipperAddress_FK

ShipperAddress

  • ShipperAddress_PK
  • ShipperState

The Orders table has data that looks like the following:

Order_PK   OrdersTypeA_FK    OrdersTypeB_FK    OrdersTypeC_FK    Customer_FK
--------   --------------    --------------    --------------    -----------
1          1                 null              null              1
2          null              1                 null              2
3          null              null              1                 3

My issue is that I need to have the select join statement retrieve the ShipperAddress by finding the Shipper_FK from one of the three OrdersType tables. The Orders table will only have one of the OrdersType FK per row. The only thing I need to retreive from the OrdersType table is the Shipper_FK so that I can join to the ShipperAddress table.

So how does the join look???

select 
ShipperAddress.ShipperState 
from Customers
left join Orders on Orders.Customer_FK = Customers.Customer_PK

????????

left join Shippers on Shipper_PK = ??????.Shipper_FK
left join ShipperAddress on ShipperAddress.ShipperAddress_PK = Shippers.ShipperAddress_FK

I can’t have a separate join down to ShipperAddress for each of the OrdersType tables. This is a smaller sample of an issue that has many more tables at the OrdersType level. The Shipper_FK is the same in each of the OrdersType tables. I need to get at the Shipper_FK no matter what OrdersType table it came from to continue with the join statement. How can that be done?

  • 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-05T22:26:30+00:00Added an answer on June 5, 2026 at 10:26 pm

    This is going to be fun to read, optimize and maintain…

    SELECT sa.ShipperState  --, other columns surely
    FROM dbo.Customers AS c
    LEFT OUTER JOIN dbo.Orders AS o 
    ON o.Customer_FK = c.Customer_PK
    LEFT OUTER JOIN dbo.OrdersTypeA AS oa
      ON oa.OrdersTypeA_PK = o.OrdersTypeA_FK
    LEFT OUTER JOIN dbo.OrdersTypeB AS ob
      ON ob.OrdersTypeB_PK = o.OrdersTypeB_FK
    LEFT OUTER JOIN dbo.OrdersTypeC AS oc
      ON oc.OrdersTypeC_PK = o.OrdersTypeC_FK
    LEFT OUTER JOIN dbo.Shippers AS s
      ON s.Shipper_PK = COALESCE(oa.Shipper_FK, ob.Shipper_FK, oc.Shipper_FK)
    LEFT OUTER JOIN dbo.ShipperAddress AS sa
      ON s.ShipperAddress_FK = sa.ShipperAddress_PK;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write a SQL-Server query but I don't know how to solve.
I need to write a query in sql server to data get like this.
I need to write this query in SQL Server: IF isFloat(@value) = 1 BEGIN
I need some help to write some queries. For this sql query (select *
need help/guide for sql select query, I have 2 table stock and stock_history, in
I am trying to write my SQL Server 2008 query in such a way
I am trying to write a Stored Procedure in SQL Server (2005) to do
I am using SQL Server 2000 and want to write a simple query to
I have to write a component that re-creates SQL Server tables (structure and data)
I have two SQL Server databases, and I need to write a script to

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.