code_junkie

SQL - Difference between Select Unique and Select Distinct

Nov 12th, 2011
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. Select Unique col from
  2. (select col from table1 union select col from table2) alias
  3.  
  4. Select Distinct col from
  5. (select col from table1 union select col from table2) alias
  6.  
  7. Create Table Employee(
  8. Emp_PKey Int Identity(1, 1) Constraint PK_Employee_Emp_PKey Primary Key,
  9. Emp_SSN Numeric Not Null Unique,
  10. Emp_FName varchar(16),
  11. Emp_LName varchar(16)
  12. )
  13.  
  14. Select Distinct Emp_LName
  15. From Employee
  16.  
  17. select col from table1
  18. union
  19. select col from table2
  20.  
  21. select col from table1
  22. union all
  23. select col from table2
Add Comment
Please, Sign In to add comment