Select Statement

The SELECT statement allows we to get the data from table of views. A table consists of rows and columns like a spreadsheet. The SELECT statement controls which columns and rows that we want to see.

For example, if we are only interested in the student name and course of all student or we just want to view the information of every student whose course is the DCA, the SELECT statement helps we to do this.

SELECT column_1, column_2, FROM table_1 [INNER/ LEFT/ RIGHT] JOIN table_2 ON condition WHERE conditions GROUP BY column_1 HAVING group_condition 
ORDER BY column_1
LIMIT offset, length;

The SELECT statement allows you to query partial data of a table by specifying a list of columns separated by commas. For instance, if you want to view only student name and course of the student, we use the following query:

Select studentname, course from student;

If you want to get data for all columns in the student table, you can list all column names in the SELECT clause, or you just use the asterisk (*) to indicate that you want to get data from all columns of the table like he following query:

select * from student;

WHERE clause

We use the WHERE clause to filter the result based on some conditions. The filter could be a range; single value or sub query.

Syntax:

SELECT* FROM tableName WHERE condition;

The filter is a combination of one or more conditions using he logical operator AND, OR, NOT. Any row from the table_name that causes he search_condition to evaluate to true will be included in the final result set.

Besides the SELECT statement, you can use the WHERE clause in the UPDATE and DELETE statement to specify which rows to update and delete.

Example:

SELECT * FROM 'products' WHERE price>2000