WHERE Condition in SQL

WHERE Condition in SQL

WHERE Condition in SQL

Interested in above project ,Click Below
WhatsApp
Telegram
LinkedIn

WHERE Condition in SQL

The WHERE condition in SQL is an essential clause used to filter records based on a specified condition. It helps retrieve only those rows that meet the defined criteria, ensuring precise data extraction. Whether used in a SELECT, UPDATE, or DELETE statement, the WHERE condition plays a crucial role in database operations by applying filters to retrieve only relevant records.

Complete Python Course with Advance topics:-Click Here
SQL Tutorial :-Click Here

Understanding the WHERE Condition

The WHERE condition is used when fetching data from a single table or multiple joined tables. If the given condition is met, only the qualifying rows are returned. This helps in extracting accurate data while optimizing database queries efficiently.

Syntax of WHERE Condition

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

Key Points About WHERE Condition:

  • The WHERE condition is not limited to the SELECT statement; it is also used with UPDATE and DELETE statements.
  • It supports various comparison and logical operators such as =, >, <, LIKE, NOT, BETWEEN, IN, etc.
  • It is case-sensitive in some databases and requires exact string matches within single quotes ('').


Example of WHERE Condition in SQL

Let’s consider a sample table named EMPLOYEES, which contains employee details:

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 EmployeeID, EmployeeName, and Salary for employees earning more than 50,000, we use the following query:

See also  SQL ORDER BY Clause with Ascending Order

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 we need to find details of a specific employee, such as Sohan Verma, we 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 in single quotes (').
  • Numeric values do not require quotes.
  • The WHERE condition can be combined with logical operators like AND, OR, and NOT for more complex filtering.

Download New Real Time Projects :-Click here
Complete Advance AI topics:- CLICK HERE

Conclusion

The WHERE condition in SQL is a fundamental clause that helps filter data efficiently. Whether retrieving specific records, updating certain values, or deleting unwanted data, the WHERE clause ensures accuracy in database queries. Mastering this concept is crucial for anyone working with SQL databases.

For more SQL tutorials and updates, visit UpdateGadh!


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

See also  SQL SELECT NULL

    🎓 Need Complete Final Year Project?

    Get Source Code + Report + PPT + Viva Questions (Instant Access)

    🛒 Visit UpdateGadh Store →
    💬 Chat Now