Posts

Showing posts from November, 2017

Difference between Group By and Distinct - SQL

Image
Introduction DISTINCT  is used to filter unique records out of the records that satisfy the query criteria . The " GROUP BY " clause is used when you need to group the data and it s hould be used to apply aggregate operators to each group .  Sometimes, people get confused when to use DISTINCT and when and why to use GROUP BY in SQL queries. Let’s understand how and when to use DISTINCT and GROUP BY. DISTINCT When you have a result set containing more than one duplicate records, then you can get unique results out of that by using DISTINCT. For example, we have Products table and there are some products with its price and get all the data from that which will contain duplication. The right column is having unique records by using DISTINCT keyword. SELECT   Name , Price  FROM  Products ORDER   BY   Name SELECT  DISTINCT  Name , Price FROM  Products ORDER   BY   Name GROUP  BY GRO...