2. msbacademy.org
Group By
The SQL GROUP BY clause is used in collaboration with
the SELECT statement to arrange identical data into groups. This
GROUP BY clause follows the WHERE clause in a SELECT
statement and precedes the ORDER BY clause
3. msbacademy.org
Syntax
SELECT column1, column2
FROM table_name
WHERE [ conditions ]
GROUP BY column1, column2
ORDER BY column1, column2;
Ex: SELECT emp_name,salary
FROM employee
WHERE salary>20000
GROUP BY emp_name
ORDER BY emp_id;
4. msbacademy.org
Order By Clause
Order By Clause is used to arrange the data either in
ascending or descending order. By default order by clause
arrange or sort the data in ascending order. To sort the records in
a descending order, you can use the DESC keyword.
Note: You can apply for an order by clause on more than one
column in the same table
8. msbacademy.org
Alias Example
For table: SELECT e.emp_id, e.emp_name, o.amount
FROM employee AS e, orders AS o
WHERE e.emp_id= o.emp_id;
For column:
SELECT student_id AS id,
student_name AS name
FROM student;