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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:00:15+00:00 2026-06-07T15:00:15+00:00

I have a table that reuses a foreign key and I’d like to join

  • 0

I have a table that reuses a foreign key and I’d like to join a different value for each case. The first table describes a drug dosing activity. It has ID’s that point to drugs, routes, vehicles, etc… The confusing thing is that it reuses the Unit ID which is a foreign key in a single description table.

GROUPS (Simplified)

GROUP_NO    DRUG      DRUG_AMOUNT     DRUG_UNIT     CHECK_UNIT
   1        568           5               7              5
   2        689           1               7              5
   2        568           5               7              5
   3        19            0.5            10             
   4        984           10             10              5

UNITS (Simplified)

UNIT_ID      UNIT_DESCR
   5         kg
   7         mg
   10        mL

I’d like to generate a query that returns a row for each drug dose for all groups. I can do everything but the units. I’d like to use a CASE statement to display the dosing units. The select statement would look something like this:

'DOSE UNITS' =
CASE
WHEN CHECK_UNIT IS NULL THEN DRUG_UNIT_DESCR
ELSE CONCAT(DRUG_UNIT_DESCR+'/'+CHECK_UNIT_DESCR)
END

I’m trying to get the results to look like such for this example:

RESULT

GROUP_NO      DRUG          DRUG_AMOUNT     'DOSE UNITS'
    1       HelpsAlot           5              mg/kg
    2       HelpsMore           1              mg/kg
    2       HelpsAlot           5              mg/kg
    3       DoesNothing         0.5            mL
    4       WhoKnows            10             mL/kg

Thanks for any 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-07T15:00:18+00:00Added an answer on June 7, 2026 at 3:00 pm

    You need two joins, one for each key:

    select g.*,
           'DOSE UNITS' = (CASE WHEN CHECK_UNIT IS NULL THEN du.UNIT_DESCR
                                ELSE CONCAT(du.UNIT_DESCR+'/'+cu.UNIT_DESCR)
                           END) 
    from groups g left outer join
         units cu
         on g.check_unit_id = cu.unit_id left outer join
         units du
         on g.drug_unit_id = du.unit_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that looks like this: id value AGA 0.211 AGA 0.433
I have a table that looks like this: CREATE TABLE foobar ( id SERIAL
I have a table that looks like this: ID (pk,int) Col1 (nvarchar) Col2 (nvarchar)
I have two views that render a table on each. Most of the tables
I have a table-value function that takes an ID number of a person and
I have table that I insert data with following query (from c# code): INSERT
I have table that contain date and time field. id|date|time ========= 1|01/01/2001|10:45 2|01/02/2002|11:45 3|01/03/2003|12:45
I have a table that contains multiple dropdown menus for a list of profile
I have a table that acts as a dropbox for files that get automatically
I have a table that has account numbers in (account_num) and user profiles (profile_id).

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.