Note: SQL DISTINCT is available only in MS SQL not MySQL

Select Distinct * from table

removed duplicates rows not duplicate column. DISTINCT works on rows not column. If you join two tables lets say

Doctors                                                             Appointment (Patients)

doc_id | Doc_Name                             Patient Name, doc_id

If you left join on doc_id, it will produce a table with doctor name repeated more than once for each appointment he has. Using distinct will not solve the problem because the rows are already distinct different (Each doctor had a different appointment) so in each row the patient name is different in front of the same doctor.

This entry was posted in SQL Server 2008. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s