SQL Where Clause
In SQL, the WHERE clause is used to
filter the rows returned by a SELECT statement based on specified
conditions. The syntax for using the WHERE clause in a SELECT
statement is as follows:
SELECT column1, column2, ... FROM table_name WHERE condition;
Here, column1, column2, etc. are the names of the columns that you want to retrieve data from,
table_name is the name of the table containing those columns, and condition is the filtering condition that you want to apply to the data.
The condition can be any valid SQL expression that evaluates to a Boolean value (TRUE or FALSE). For example, if you have a table employees with columns name, department, and salary, and you want to retrieve only the employees with a salary greater than 50000, you can use the following query:
SELECT name, department FROM employees WHERE salary > 50000;
This will return only the names and departments of the employees whose salary is greater than 50000. The WHERE clause can be combined with other keywords like AND, OR, and NOT to create more complex conditions.
The SQL WHERE clause is used to filter data based on specified conditions. It is used in conjunction with the SELECT, UPDATE, DELETE, and other SQL statements that modify data. It has the following syntax:
SELECT column1, column2, ...
FROM table_name
WHERE condition;
· SELECT column1, column2, ...: specifies the columns you want to retrieve data from.
· FROM table_name: specifies the table you want to retrieve data from.
· WHERE condition: specifies the condition that the data must meet in order to be retrieved.
Here are some examples of the SQL WHERE clause:
SELECT *
FROM customers
WHERE country = 'USA';
This statement retrieves all the columns from the "customers" table where the "country" column is equal to 'USA'.
UPDATE orders
SET status =
'completed'
WHERE customer_id = 123;
This statement updates the "status" column of the "orders" table to 'completed' where the "customer_id" column is equal to 123.
DELETE FROM
customers
WHERE city = 'New York';
This statement deletes rows from the "customers" table where the "city" column is equal to 'New York'.
0 Comments