The SQL DISTINCT keyword is used in conjunction with SELECT statement to eliminate all the duplicate records and fetching only unique records.
There may be a situation when you have multiple duplicate records in a table. While fetching such records, it makes more sense to fetch only unique records instead of fetching duplicate records.
There may be a situation when you have multiple duplicate records in a table. While fetching such records, it makes more sense to fetch only unique records instead of fetching duplicate records.
The basic syntax is as follows:
| SELECT DISTINCT Column_Name(s) FROM Table_Name WHERE Conditions | 
Syntax For SQL:
| SELECT DISTINCTDept_id FROM Employee | 
| Employee | ||||
| Emp_id | Name | Surname | Salary | Dept_id | 
| 1 | Rajesh | Khanna | 45000 | 2 | 
| 2 | Sneha | Gupta | 55000 | 4 | 
| 3 | Sandeep | Nehte | 95000 | 1 | 
| 4 | Kirti | Patil | 25000 | 3 | 
| 5 | Nilesh | Jadhav | 45000 | 3 | 
| 6 | Dipesh | Das | 35000 | 5 | 
| 7 | Kailash | Rane | 62000 | 1 | 
| 8 | Kavita | Deshpande | 48000 | 3 | 
| 9 | Sanjay | Datt | 50000 | 3 | 
| 10 | Shruti | Hasan | 78000 | 1 | 
After Execute:
| Dept_id | 
| 2 | 
| 4 | 
| 1 | 
| 3 | 
| 5 | 
 
 
 
 
 
   
No comments:
Post a Comment