0
0
C Sharp (C#)programming~5 mins

Where clause filtering in C Sharp (C#)

Choose your learning style9 modes available
Introduction

The WHERE clause helps you pick only the rows you want from a table. It filters data based on conditions.

You want to find all customers from a specific city.
You need to get orders placed after a certain date.
You want to list products with a price less than $20.
You want to see employees in a certain department.
You want to filter records where a status is 'active'.
Syntax
C Sharp (C#)
SELECT column1, column2 FROM table_name WHERE condition;
The condition can use operators like =, >, <, >=, <=, <> (not equal).
You can combine conditions with AND, OR for more filtering.
Examples
Gets all customers who live in London.
C Sharp (C#)
SELECT * FROM Customers WHERE City = 'London';
Shows product names and prices for items cheaper than $20.
C Sharp (C#)
SELECT Name, Price FROM Products WHERE Price < 20;
Finds orders shipped on or after January 1, 2024.
C Sharp (C#)
SELECT * FROM Orders WHERE OrderDate >= '2024-01-01' AND Status = 'Shipped';
Sample Program

This query lists all employees who work in the Sales department.

C Sharp (C#)
SELECT EmployeeID, FirstName, LastName FROM Employees WHERE Department = 'Sales';
OutputSuccess
Important Notes

Text values in conditions must be in single quotes.

Be careful with case sensitivity depending on your database.

Use parentheses to group conditions when combining AND and OR.

Summary

The WHERE clause filters rows based on conditions.

Use comparison operators and logical operators to build conditions.

It helps get only the data you need from a table.