i

PHP Tutorial

MySQL Commands-Where and Order By

Where is a clause in SQL used to filter the data based on a condition. The rows that fulfills the condition will be selected using Where statement.

Syntax: SELECT column1, column2,.. FROM table_name WHERE column_name operator value

For example: SELECT visitor_id, name from Visitors WHERE name = ‘Paul’;

When you want to sort the data stored in a table and view it, you can use ORDER BY clause. You can use to sort the data in ascending or descending. By default, data will be sorted based on ascending order.

Syntax: SELECT column1, column2, .. FROM table_name ORDER BY column_name ASC|DESC

For example: SELECT visitor_id, name from Visitors ORDER BY name; //in ascending