Where Clause MySQL Essential Training

Where Clause MySQL Essential Training

MYSQL

Where Clause MySQL Essential Training




In this lesson we’re gonna learn the functions of the Where Clause MySQL Essential Training. In this lesson we can understand the capabilities of the Where clause when we using the Select statement.
If you use the SELECT statement to query the data from tables without the WHERE clause, you will get all rows in the tables that may be not necessary. The tables accumulate data from business transactions all times. It does not make sense to get all rows from a table especially for big tables like employees, sales orders, purchase orders, production orders, etc., because we often want to analyze a set of data at a time e.g, sales of this quarter, sales of this year compared to last year, etc.
The WHERE clause allows you to specify exact rows to select based on a particular filtering expression or condition.
MySQL WHERE clause examples
We will continue with the emp_details table data in the sample database as shown in the picture below.
MySQL employees table
Suppose, we just want to get artist from the emp_details table, we use the following query:

Where Clause MySQL Essential Training
From the above query we can get only the employees who are all having the artist as a designation.
In the Where Clause MySQL Essential Training lesson query the where clause may appears at the end, but the MySQL executes the where at first to find the matching rows. It selects the rows that have the designation as artist.

MySQL then selects the columns from the selection list in the SELECT clause. The highlighted area contains the columns and rows in the final result set.
You can form a simple condition like the query above, or a very complex one that combines multiple expressions with logical operators such as AND, OR, etc. For example, to find all artist in the address NewYork, you use the following query:




Where Clause MySQL Essential Training
The following table lists the comparison operators that you can use to form filtering expressions in the WHERE clause.
The following query uses the not equal to operator to get all employees who are not the artist:

Where Clause MySQL Essential Training
More on MySQL WHERE clause…
There are also some useful operators that you can use in the Where Clause MySQL Essential Training to form complex conditions such as:
BETWEEN selects values within a range of values.
LIKE matches value based on pattern matching.
IN specifies if the value matches any value in a list.
IS NULL checks if the value is NULL.
The WHERE clause is used not only with the SELECT statement but also other SQL statements to filter rows such as DELETE and UPDATE. We can some other where clause operator options in the upcoming lessons.
We hope this lesson will gives you an basic idea about the Where clause and its functions.




Leave a Reply