The MySQL WHERE statement is used to define a circumstance when the data is collected from a separate list or joined to several tables. If the specified circumstance is met, then only the unique value of the table is returned. To extract the information and retrieve only the correct records, you can use the WHERE statement.
Not only, the WHERE condition used in the Selection statement, but it is also used in the UPDATE assertion, DELETE assertion, etc.
Syntax
Now, we have discussed the syntax of the SELECT statement associated with the WHERE condition. It is shown below-
SELECT column1, column2, ..... columnN
FROM table_name
WHERE {condition}
Note: The WHERE condition is used not only in the Selection assertion but also in the UPDATE assertion, the Remove assertion, etc.!
You may use contrast or logical operators, such as >, <, =, LIKE, NOT, etc. To define a state. The below-given example will explicitly state this notation.
For Example-
Here, we consider the table of CUSTOMERS with the below-given records.
CustomerID | CustomerName | Address | Age | Salary |
---|---|---|---|---|
001 | Hardy Thompson | Maxico | 25 | 10000.00 |
002 | Sturt Broad Los Angeles | 28 | 25000.00 | |
003 | Joseph Winget | California | 30 | 56000.00 |
004 | David Anderson | Norway | 24 | 76000.00 |
005 | Alexa | Denmark | 35 | 23000.00 |
Now, we will run the below-given query on SQL to fetch the CustomerID, CustomerName and Salary from the above table CUSTOMERS, where the salary is greater than 25000.
Select CustomerID, CustomerName, Salary
from CUSTOMERS
Where Salary > 25000;
Output
After the successful execution of the above SQL query, we got the following output.
Here, we have another instance where we would get the CustomerID, CustomerName and Salary from the database table named CUSTOMERS for a specific customer named Joseph Winget.
Select CustomerID, CustomerName, Salary
from CUSTOMERS
Where CustomerName = 'Joseph Winget';
Output
After the successful execution of the above SQL query, we got the above-given outcome.
Leave a Reply