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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:23:32+00:00 2026-06-05T14:23:32+00:00

I have one very large, un-normalized table which I am in the process of

  • 0

I have one very large, un-normalized table which I am in the process of fixing. From that large table I’m normalizing the data. I used the SQL statement

INSERT INTO smallTable(patientID, admissionDate, dischargeDate)
select distinct patientID, admissionDate, dischargeDate
FROM largeTable

So my smallTable is populated with the correct number of rows. There’s another column, drgCode that I want to add to my smallTable. I tried the following query to do that

INSERT INTO smallTable(drgCode)
select drgCode from
(
SELECT DISTINCT patientID, admissionDate, dischargeDate, drgCode from largeTable) as t

The error I was given reads cannot insert the value NULL into patientID, column does not alloq nulls, insert fails.

The only way that the drgCode will be chosen correctly is if some variant of the select distinct query is used. How can I insert only one field, when the other fields must be included to narrow down the search.

I know I could do this if I emptied out my smallTable, but I figured there’s gotta be a way around it.

  • 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-05T14:23:33+00:00Added an answer on June 5, 2026 at 2:23 pm
        with    drg as (SELECT DISTINCT patientID, admissionDate, dischargeDate, drgCode from largeTable)
        update  s
        set     s.drgCode = l.drgCode
        from    smallTable s join drg l on 
                    s.patientId = l.patientId and
                    s.admissionDate = l.admissionDate and
                    s.dischargeDate  = l.dischargeDate
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to migrate a very large dataset from one system to another. One
I have a very large database with about 120 Million records in one table.I
I have two very large enterprise tables in an Oracle 10g database. One table
I have a very large data set that I'm trying to find the smallest
I have a very large table (800GB) which has a DATETIME field which is
I have two very large(30000+ documents) collections, one contains words extracted from a text
I have a very large class, which is very documented. Doxygen is used for
I have a very large html table that is similar to the following: <table>
I have two arrays, one is very large (more than million entries) and other
I have UITableView with very large cells with lots of content (more than one

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.