WHERE
Example
Section titled “Example”SELECT *FROM EmployeesWHERE salary > 50000;Output
Section titled “Output”| employee_id | first_name | last_name | position | hire_date | salary ||-------------|------------|-----------|-----------|------------|--------|| 2 | John | Smith | Developer | 2018-06-10 | 60000 || 5 | Jane | Doe | Manager | 2017-01-15 | 75000 |Explanation
Section titled “Explanation”In the above example, WHERE clause is used to filter records. It extracts only those employees from the Employees table whose salary is greater than 50000. All columns of the filtered records are returned and displayed.
Example
Section titled “Example”SELECT * FROM EmployeesWHERE FirstName = 'John';Output
Section titled “Output”| EmployeeID | FirstName | LastName | JobTitle ||------------|-----------|----------|-----------------|| 1 | John | Doe | Software Engineer|Explanation
Section titled “Explanation”In the given example, the SELECT * FROM Employees WHERE FirstName = 'John'; SQL statement is selecting all records (*) from the Employees table where the FirstName is 'John'. This returned a single record where the FirstName is 'John'.
Example
Section titled “Example”SELECT *FROM EmployeesWHERE Department = 'Sales';Output
Section titled “Output”| EmployeeId | First Name | Last Name | Department ||------------|------------|-----------|------------|| 1 | John | Doe | Sales || 2 | Jane | Smith | Sales |Explanation
Section titled “Explanation”The SQL command in the example demonstrates the use of the WHERE clause to filter rows in a table. In this case, only employees working in the ‘Sales’ department are returned in the result.
Example
Section titled “Example”SELECT * FROM employeesWHERE salary > 5000;Output
Section titled “Output”| Employee_ID | First_Name | Last_Name | Email | Salary ||-------------|------------|-----------|-------------|------- || 100 | Nancy | Greenberg | nancy@abc.com| 6000 || 105 | John | Smith | john@abc.com | 7000 |Explanation
Section titled “Explanation”The example query selects all columns from the employees table where the salary is greater than 5000.
Example
Section titled “Example”SELECT *FROM CustomersWHERE Country='Germany';Output
Section titled “Output”| CustomerID | CustomerName | ContactName | Country ||------------|--------------|-------------|---------|| 2 | Ana Trujillo | Ana Trujillo | Germany || 5 | Berglunds snabbköp | Christina Berglund | Germany || 9 | Bólido Comidas preparadas | Martín Sommer | Germany |Explanation
Section titled “Explanation”The WHERE clause in the SQL statement is used to extract only the records that fulfill a specified condition. In the example above, only the records where the Country is ‘Germany’ are extracted from the Customers table.