0% found this document useful (0 votes)
242 views1 page

SQL Exercise - Tenet Healthcare

The document contains several SQL questions and answers: 1) A query to identify duplicate patient IDs in a patient table by counting occurrences and returning rows where the count is greater than one. 2) A delete statement to remove duplicate patient IDs from the table to make it unique on that column. 3) A plus sign in parentheses is commonly used in Oracle SQL to perform an outer join between two or more tables.

Uploaded by

Bhaskar Reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
242 views1 page

SQL Exercise - Tenet Healthcare

The document contains several SQL questions and answers: 1) A query to identify duplicate patient IDs in a patient table by counting occurrences and returning rows where the count is greater than one. 2) A delete statement to remove duplicate patient IDs from the table to make it unique on that column. 3) A plus sign in parentheses is commonly used in Oracle SQL to perform an outer join between two or more tables.

Uploaded by

Bhaskar Reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

1)

Table PATIENT has columns PATIENT_ID, FNAME, and LNAME. Write a query that will
identify duplicate PATIENT_IDs in the table PATIENT. The query should return all
three columns and include all rows where the PATIENT_ID shows up more than once
in the table.
SELECT PATIENT_ID, FNAME, LNAME , COUNT(PATIENT_ID) AS
NUMOFOCCURENCES
FROM PATIENT
GROUP BY PATIENT_ID
HAVING COUNT(PATIENT_ID)>1
2)
Write a delete statement to remove the duplicates on PATIENT_ID. It does not
matter which duplicates are deleted but the table must be unique on PATIENT_ID
after the delete statement.
DELETE FROM PATIENT WHERE PATIENT_ID
IN ( SELECT PATIENT_ID,FNAME,LNAME FROM PATIENT GROUP BY PATIENT_ID
HAVING ( COUNT(PATIENT_ID) > 1)
)
3)
What is a plus sign enclosed by parentheses commonly used for in ORACLE SQL.
When we are looking to see data from two or more tables we use (+ ) to join
the tables.
4)
Read the below SQL
Select * from patient, orders
Where patient.patient_id = orders.patient_id (+)
And orders.order_type = 705
What type of join is in the above query?
Outer Join
5)
Two tables, TABLE_A and TABLE_B have the same structure. There are no
constraints on either of the tables. How can you verify that TABLE_A and TABLE_B
contain the same data.
One way is to use an left outer join this selects all in the first table and then
matches these in the second. If the extra columns coming from the second table a
NULL then there is no matching record in the second.

You might also like