How can multiple criteria be used in the ORDER BY clause in MySQL when sorting a table?
When sorting a table in MySQL using the ORDER BY clause, multiple criteria can be used by separating them with commas. This allows for sorting based on more than one column in the table, providing a more specific and customizable sorting order. By specifying multiple criteria in the ORDER BY clause, you can control the order in which the records are returned based on different columns or expressions.
$query = "SELECT * FROM table_name ORDER BY column1 ASC, column2 DESC";
$result = mysqli_query($connection, $query);
if(mysqli_num_rows($result) > 0){
while($row = mysqli_fetch_assoc($result)){
// Output data
}
} else {
echo "No records found";
}