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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:10:31+00:00 2026-06-11T00:10:31+00:00

I have 4 tables and would like to return the tables in the most

  • 0

I have 4 tables and would like to return the tables in the most efficient manner where the keys map to their correct entries.

Table A columns:

[ SVC_PREFIX | SVC_CD | ... ]

Table B columns:

[ SVC_PREFIX | SVC_CD | SVC_ID |... ]

Table C columns:

[ SVC_ID | ... ]

Table D columns:

[ SVC_ID | ... ]

Table A maps to Table B by SVC_PREFIX and SVC_CD
Table B is then responsible for retrieving Table C and D via SVC_ID
Table C and D are nearly the same except Table D has a few less columns than C
For instance, C may have a isGood and isSilly but D will only have isSilly.
Is it possible to retrieve the entries such that D will be pulled with a NULL value for isSilly while C will bring the corresponding data?

Here’s an example:
Table A columns:

[ SVC_PREFIX | SVC_CD | anotherData ]
[ 111 | 123 | AAA ]

Table B columns:

[ SVC_PREFIX | SVC_CD | SVC_ID ]
[ 111 | 123 | 007]

Table C columns:

[ SVC_ID | isGood | isHappy ]
[ 007 | Y | Y ]

Table D columns:

[ SVC_ID | isGood ]
[ 007 | Y ]

Data I’d like to retrieve:

[ SVC_PREFIX | SVC_CD | anotherData | SVC_ID | isGood | isHappy ]

Actual data

[ 111 | 123 | AAA | 007 | Y | Y ]
[ 111 | 123 | AAA | 007 | Y | NULL ]

I’d like to display both C and D’s table as separate rows.

Currently, I have an implicit join, but does not achieve the result I desire…

SELECT *
FROM A,B,C,D
WHERE A.SVC_PREFIX = B.SVC_PREFIX
AND A.SVC_CD = B.SVC_CD
AND B.SVC_ID = C.SVC_ID
AND B.SVC_ID = D.SVC_ID
AND C.SVC_ID = D.SVC_ID

Thanks for the help!

  • 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-11T00:10:32+00:00Added an answer on June 11, 2026 at 12:10 am

    You can use a UNION. I believe this would work in SQL Server.

    SELECT A.SVC_PREFIX, B.SVC_CD, A.anotherData, CD.SVC_ID, CD.isGood, CD.isHappy  
    FROM A
    JOIN B ON B.SVC_PREFIX = A.SVC_PREFIX AND B.SVC_CD = A.SVC_CD
    JOIN
    (
      SELECT SVC_ID, isGood, isHappy
      FROM C
    
      UNION
    
      SELECT SVC_ID, isGood, NULL AS isHappy
      FROM D
    ) AS CD ON CD.SVC_ID = B.SVC_ID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL table and would like to return the rows based on
I have a few tables with 70-80 columns in them. I would like to
I have two tables user and log. I would like to join the user
I have two tables, name and address. I would like to list the last_name
I have two tables: Companies: (id, name) Workers: (id, name, country) I would like
I have two different tables, lead and click. I would like to query MySQL
I have a couple of tables (mySQL) that i would like to update with
I have a couple of tables that are transaction tables, and I would like
I have a table and I would like to be able to set up
I have a Customers table and would like to assign a Salesperson to each

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.