SQL Tutorial

WHERE Condition in SQL

WHERE Condition in SQL
WHERE Condition in SQL

WHERE Condition in SQL

The WHERE condition is one of the most important clauses in SQL for filtering records according to a specific condition. It allows you to retrieve only the rows that match the given criteria, making data extraction more precise.

The WHERE condition can be used with SELECT, UPDATE, and DELETE statements and plays an important role in performing database operations on relevant records.

WHERE Condition in SQL

Complete Advance AI Topics: Click Here
SQL Tutorial:
Click Here

Understanding the WHERE Condition

The WHERE condition is used when retrieving information from a single table or from multiple joined tables. When the specified condition is satisfied, only the matching rows are returned.

This makes it easier to obtain the required records instead of processing or displaying unrelated data.

Syntax of WHERE Condition

SELECT column1, column2, ..... columnN
FROM table_name
WHERE {condition};

Key Points About WHERE Condition

  • The WHERE condition is not restricted to SELECT; it can also be used with UPDATE and DELETE statements.
  • It supports different comparison and logical operators, including =, >, <, LIKE, NOT, BETWEEN, and IN.
  • It can be case-sensitive in some databases, and string values require exact matching within single quotes ('').

Example of WHERE Condition in SQL

Let’s consider a sample table named EMPLOYEES containing employee information:

EmployeeIDEmployeeNameDepartmentAgeSalary
101Aryan SharmaIT2755000.00
102Meera RajHR3062000.00
103Sohan VermaFinance2848000.00
104Kiran DasMarketing3272000.00
105Rohan MehtaIT2651000.00

Fetching Employees with Salary Greater than 50,000

To retrieve the EmployeeID, EmployeeName, and Salary of employees whose salary is greater than 50,000, use the following query:

SELECT EmployeeID, EmployeeName, Salary
FROM EMPLOYEES
WHERE Salary > 50000;

Output

EmployeeIDEmployeeNameSalary
101Aryan Sharma55000.00
102Meera Raj62000.00
104Kiran Das72000.00
105Rohan Mehta51000.00

Fetching Employee Details by Name

If you want to retrieve the details of a particular employee, such as Sohan Verma, you can use the following query:

SELECT EmployeeID, EmployeeName, Salary
FROM EMPLOYEES
WHERE EmployeeName = 'Sohan Verma';

Output

EmployeeIDEmployeeNameSalary
103Sohan Verma48000.00

Important Notes

  • String values should always be enclosed within single quotes, such as 'Sohan Verma'.
  • Numeric values do not require quotation marks.
  • The WHERE condition can be combined with logical operators such as AND, OR, and NOT to create more complex filters.

Download New Real Time Projects :- Click here

Complete Advance AI topics:-

Conclusion

The WHERE condition is a fundamental SQL clause used to filter data efficiently. Whether you are retrieving specific records, updating selected values, or removing unwanted records, the WHERE clause helps ensure that database operations are performed on the required data.

Understanding and mastering the WHERE condition is essential for anyone working with SQL databases.


SEO Keywords

sql where multiple conditions, where clause in sql example, having clause in sql, order by clause in sql, group by clause in sql, sql where clause multiple values, having clause with where condition in sql, select clause in sql, order by in sql, WHERE Condition in SQL, like in sql, where condition in sql w3schools, where condition in sql server

Source Code Available

Interested in This Project?

Get the complete source code for this project at a very affordable price — perfect for your portfolio, college submission, or learning. Message us on WhatsApp and we'll get back to you instantly!

Full source code included Step-by-step setup guide Instant delivery on WhatsApp Instant reply on WhatsApp
Chat on WhatsApp

We usually reply within a few minutes

Leave a Reply

Your email address will not be published. Required fields are marked *

Chat with us