91-9990449935 0120-4256464 |
PostgreSQL GROUP BY ClauseThe PostgreSQL GROUP BY clause is used to group together those rows in a table that have identical data. It is used with SELECT statement. The GROUP BY clause collects data across multiple records and groups the result by one or more columns. It is also used to reduce the redundancy in the output. Syntax: Note: In case of GROUP BY multiple columns you make sure whatever column you are using to group, that column should be available in column-list. See this example: Let's take a table "EMPLOYEES" having the following data. Execute the following query: Output: How it reduce redundancy:See this example: Let's insert some duplicate records in the "EMPLOYEES" table. Add the following data: Output: Execute the following query to see the redundancy: Output: Note: In the above example you can see that the duplicate names are merged when we use GROUP BY "NAME". It specifies that GROUP BY reduces redundancy.
Next TopicPostgreSQL Having Clause
|