Reputation: 619
I have imported the data into an database.
Patient(pt_id,pt_name,pt_type,pt_loc)
Now , I want to find which of these a primary (have unique) values.
Any way I could found is
select count(pt_id) from patient
select count(distinct pt_id) from patient
would return the same value
Any input would be great :)
Thanks!!!
Upvotes: 0
Views: 111
Reputation: 12940
A single-pass method of determining if the column contains only unique values would be:
SELECT pt_id, COUNT(pt_id) from patient
GROUP BY pt_id
HAVING COUNT(pt_id) > 1
if you get results, it's not unique. You may also want to check for nulls:
SELECT * from patient
WHERE pt_id is NULL
Upvotes: 4