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 ColumnsSELECT employee_id,salary FROM employee ORDER BY salary
Specifying sort directionSELECT 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%';