How to use  GROUP BY Multiple Columns in SQL In SQL

In the SQL GROUP BY clause we use the SELECT statement to arrange similar data into groups.

Syntax:

SELECT column1, column2, …
FROM table_name
WHERE condition
GROUP BY column1, column2, …
ORDER BY column1, column2, …

Let’s have a look into the GROUP BY clause by seeing some queries.

Query:

CREATE TABLE demo_table(
NAME VARCHAR (20),
AGE INT ,
CITY VARCHAR(20)
);
INSERT INTO demo_table (NAME, AGE, CITY) VALUES
('Aman Chopra', 25, 'New York'),
('Shubham Thakur', 30, 'Los Angeles'),
('Naveen Tulasi', 45, 'Chicago'),
('Aditya Arpan', 28, 'Miami'),
('Nishant Jain', 50, 'Houston');

Output:

 

Query:

SELECT AGE, CITY
FROM demo_table 
WHERE AGE<30
GROUP BY AGE
ORDER BY AGE;

Output:

 

Conclusion

  1. The UPDATE statement can be used to update a table’s columns.
  2. The UPDATE statement uses the SET command to specify the columns to update.
  3. Following the SET command, the conditions are specified using the WHERE command.
  4. Updates are made to the cells that meet the criteria.
  5. To divide up data into groups, use the GROUP BY clause.

How to Update Multiple Columns in Single Update Statement in SQL?

In this article, we will see, how to update multiple columns in a single statement in SQL. We can update multiple columns by specifying multiple columns after the SET command in the UPDATE statement. The UPDATE statement is always followed by the SET command, it specifies the column where the update is required.

Similar Reads

UPDATE for Multiple Columns

Syntax:...

Using  GROUP BY Multiple Columns in SQL

In the SQL GROUP BY clause we use the SELECT statement to arrange similar data into groups....