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

  • Home
  • SEARCH
  • 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 6076761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:38:41+00:00 2026-05-23T10:38:41+00:00

I have two tables and I am looking to merge data from one table

  • 0

I have two tables and I am looking to merge data from one table into another. Specifically, Table_A is millions of records of patient discharge’s from Hospitals; table_B tells whether a particular hospital is labeled as an Acute Care Facility. I’m wanting to grab all records from table A where the Hospital is an Acute Care Facility.

Table A has many fields; of relevance:

HOSPITAL_ID | YEAR_AND_QUARTER | RECORD_ID

With record ID being unique. There are hundreds to thousands of record’s (RECORD_ID’s) per HOSTPIAL_ID, and hundreds of HOSPITAL_IDs per YEAR_AND_QUARTER

Table_B has a few fields:

HOSPITAL_ID | YEAR_ALONE | ACUTE_INDICATOR
1223 | 2004 | X  
1223 | 2005 | X  
1289 | 2004 |  
1289 | 2005 | X  

With Hospital_ID AND Year occuring only once together.

I can’t join on Hospital_ID, because in Table B each Hospital ID occurs more than once. Also, table_B lumps all quarterly data into one year (instead of 2004Q1, 2004Q2.. only 2004).

Thus the final output (preferably as a new table) I want is just ACUTE_INDICATOR added to Table_A

HOSPITAL_ID | YEAR_AND_QUARTER | ACUTE_INDICATOR | RECORD_ID....

Appologies ahead, I’m an SQL infant and wasn’t even quite sure what to search for an answer. My best guesses were (pseudo):

INNER JOIN (SELECT B.ACUTE_INDICATOR)
ON A.HOSPITAL_ID = B.HOSPITAL_ID
WHERE LEFT(A.YEAR_AND_QUARTER,4) = B.YEAR_ALONE

Many thanks 🙂

  • 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-23T10:38:41+00:00Added an answer on May 23, 2026 at 10:38 am

    This will create the new table for you:

    SELECT
        a.HOSPITAL_ID,
        a.YEAR_AND_QUARTER,
        b.ACUTE_INDICATOR,
        a.RECORD_ID
    INTO c
    FROM
        a JOIN
        b ON a.HOSPITAL_ID = b.HOSPITAL_ID 
            AND LEFT(a.YEAR_AND_QUARTER, 4) = b.YEAR_ALONE
    

    Then if you wanted to query that table for Acute Care Facilities only…

    SELECT * FROM c WHERE ACUTE_INDICATOR = 'x'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two datasets each with one data table pulled from different sources and
I have two tables that I want to join into one table and use
I have two tables and I'm looking for the rows in one table where
I have two tables that get joined regularly. Table One is about 1 Million
I have two tables, one an import table, the other a FK constraint on
I have a query which searches two separate fields in the same table... looking
I have two tables, one that contains volunteers, and one that contains venues. Volunteers
I have two tables: Table 1: ID, PersonCode, Name, Table 2: ID, Table1ID, Location,
I have two tables which both contain 'pipe separated values' e.g: Table 1: DataField_A
I'm looking for a query to select rows from two different tables, keeping the

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.