Advertisement

10.17.2007 at 11:37PM PDT, ID: 22901026
[x]
Attachment Details

Oracle SQL distinct query

Asked by huzefaq in MS SQL Server, Oracle Database, PL / SQL

Tags: distinct, oracle, sql

Hello All,

I have two tables in oracle database.
1) MOTDC_STG_SHIP_CONF_HEADER_TMP
2) MOTDC_STG_SHIP_CONF_HEADER

Both tables are identical, only first table (MOTDC_STG_SHIP_CONF_HEADER_TMP)  does not have any unique constraint and has lots of duplicate data.  And 2nd Main table has unique contraint on transaction_id, CONTAINER_ID, CONTAINER_TYPE, and does not have duplicate data.  

I want to select all distinct records based on transaction_id, CONTAINER_ID, CONTAINER_TYPE from MOTDC_STG_SHIP_CONF_HEADER_TMP table and insert into the MOTDC_STG_SHIP_CONF_HEADER table.

Schema for MOTDC_STG_SHIP_CONTAINER

CREATE TABLE MOTDC_STG_SHIP_CONTAINER
(
  TRANSACTION_ID       NUMBER,
  CONTAINER_TYPE       VARCHAR2(10 BYTE),
  CONTAINER_ID         VARCHAR2(40 BYTE),
  CONTAINER_LENGTH     NUMBER(9,3),
  CONTAINER_WIDTH      NUMBER(9,3),
  CONTAINER_HEIGHT     NUMBER(9,3),
  CONTAINER_WEIGHT     NUMBER(9,3)              NOT NULL,
  CONTAINER_PACK_TYPE  VARCHAR2(10 BYTE),
  CONTAINER_TRK_NUM    VARCHAR2(50 BYTE)        NOT NULL,
  CREATION_DATE        DATE                     NOT NULL,
  CREATED_BY           NUMBER                   NOT NULL,
  LAST_UPDATE_DATE     DATE                     NOT NULL,
  LAST_UPDATED_BY      NUMBER                   NOT NULL
)

Schema for MOTDC_STG_SHIP_CONTAINER_TMP

CREATE TABLE MOTDC_STG_SHIP_CONTAINER_TMP
(
  TRANSACTION_ID       NUMBER,
  CONTAINER_TYPE       VARCHAR2(10 BYTE),
  CONTAINER_ID         VARCHAR2(40 BYTE),
  CONTAINER_LENGTH     NUMBER(9,3),
  CONTAINER_WIDTH      NUMBER(9,3),
  CONTAINER_HEIGHT     NUMBER(9,3),
  CONTAINER_WEIGHT     NUMBER(9,3)              NOT NULL,
  CONTAINER_PACK_TYPE  VARCHAR2(10 BYTE),
  CONTAINER_TRK_NUM    VARCHAR2(50 BYTE)        NOT NULL,
  CREATION_DATE        DATE                     NOT NULL,
  CREATED_BY           NUMBER                   NOT NULL,
  LAST_UPDATE_DATE     DATE                     NOT NULL,
  LAST_UPDATED_BY      NUMBER                   NOT NULL
)

Start Free Trial
[+][-]10.18.2007 at 12:22AM PDT, ID: 20099188

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.18.2007 at 12:57AM PDT, ID: 20099268

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.18.2007 at 01:00AM PDT, ID: 20099279

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.18.2007 at 01:09AM PDT, ID: 20099298

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: MS SQL Server, Oracle Database, PL / SQL
Tags: distinct, oracle, sql
Sign Up Now!
Solution Provided By: konektor
Participating Experts: 4
Solution Grade: A
 
 
[+][-]10.18.2007 at 09:09AM PDT, ID: 20102197

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628