MySQL sorting data

Explain how to sort data by providing examples for the following.

1. Sorting by Multiple Columns
2. Specifying sort direction

Sort data : The ORDER BY clause in MySQL can be used to sort the specified column. Default sorting is ascending.

Sorting by Multiple Columns
SELECT employee_id,salary FROM employee ORDER BY salary

Specifying sort direction
SELECT employee_id,salary FROM employee ORDER BY salary DESC;

State generic SQL syntax and an example of SELECT command along with LIKE clause to fetch data from MySQL table.

LIKE clause is used for pattern matching. % is used to match any string of any length where as _ allows you to match on a single character.

Syntax:
SELECT * FROM table_name
WHERE column_name like 'pattern%';
Example:
SELECT * FROM employee
WHERE emp_name like 'ma%';
MySQL where clause
MySQL where clause - Explain the use of Where clause
MySQL operator - AND, OR and IN operator
MySQL operator - The LIKE operator is used to search for a specified pattern in a column.
MySQL searching using regular expression
MySQL searching - basic character matching using REGEXP in MySQL, matching of several characters at a time
Post your comment