The WHERE clause is an optional clause in an SQL statement that is used to filter the data retrieved by the statement. The WHERE clause is used to specify the conditions that must be met in order for the data to be retrieved. The basic syntax of the WHERE clause is as follows:
SELECT column1, column2, ..., column_n FROM table_name WHERE condition;
In this syntax, the
condition represents the conditions that must be met for the data to be retrieved. The conditions in the WHERE clause can be based on various operators, such as equal to (=), not equal to (!=), greater than (>), less than (<), greater than or equal to (>=), less than or equal to (<=), and others.
Let’s take a look at a few examples to understand the WHERE clause better:
SELECT name, age, city FROM students WHERE age >= 18;
In this example, the WHERE clause specifies that only the students whose age is greater than or equal to 18 should be retrieved. The result of this query will be a table that displays the name, age, and city of all the students who are 18 years old or older in the
SELECT name, marks, subject FROM marks WHERE marks >= 80 AND subject = 'Mathematics';
In this example, the WHERE clause specifies that only the students who scored 80 or more marks in Mathematics should be retrieved. The result of this query will be a table that displays the name, marks, and subject of all the students who scored 80 or more marks in Mathematics in the
SELECT students.name, marks.subject, marks.marks FROM students JOIN marks ON students.student_id = marks.student_id WHERE students.city = 'New York';
In this example, the WHERE clause specifies that only the students who live in New York should be retrieved. The result of this query will be a table that displays the name of the student, the subject, and the marks for all the students who live in New York in the
In conclusion, the WHERE clause is a powerful tool for filtering data in SQL statements. It provides a way to retrieve data from a relational database based on specific conditions, making it easier to find the data you need.
Also check WHAT IS GIT ? It’s Easy If You Do It Smart
You can also visite the Git website (https://git-scm.com/)