← Back to MySQL Course | Chapter 6: Filtering & Sorting | Lesson 1 of 8

WHERE Clause

WHERE एक sieve जैसा है जो सिर्फ आपके rule में fit होने वाली rows को गुज़रने देता है, जैसे दस साल से बड़े सभी students।
Syntax
sql
SELECT column1, column2
FROM table_name
WHERE condition;

Filtering का Introduction

WHERE clause एक result set को filter करके सिर्फ एक specified condition से match करने वाली rows तक ले आता है, एक query को जो पूरी table return करती वह exactly आपको चाहिए records return करने वाली में बदलते हुए।

उदाहरण: Introduction to Filtering

sql
SELECT * FROM users WHERE age > 18;

Numbers से Filter करना

Numeric filtering किसी column के against directly >, <, और >= जैसे standard comparison operators इस्तेमाल करता है, जो 'all products under $50' या 'users older than 18' जैसी चीज़ें query करने का typical तरीका है।

उदाहरण: Filtering with Numbers

sql
SELECT * FROM products WHERE price < 20;

Text से Filter करना

एक WHERE condition में text values single quotes में wrapped होनी चाहिए, नहीं तो MySQL bare word को एक literal string के बजाय column name समझ लेगा और एक error raise करेगा।

उदाहरण: Filtering with Text

sql
SELECT * FROM users WHERE name = 'Amit';

Dates से Filter करना

Date literals को भी text जैसे quoted होना ज़रूरी है, YYYY-MM-DD format में लिखा गया जो MySQL expect करता है, क्योंकि एक unquoted date भी इसी तरह एक invalid column reference की तरह parse होगी।

उदाहरण: Filtering with Dates

sql
SELECT * FROM orders WHERE order_date = '2024-03-05';

Inequality Operators इस्तेमाल करना

!= या <> operator किसी specific value से match करने वाली rows को उसके लिए select करने के बजाय exclude करता है, जो एक filter में 'इस एक case को छोड़कर बाकी सब' express करने का standard तरीका है।

उदाहरण: Using Inequality Operators

sql
SELECT * FROM users WHERE status != 'inactive';
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. text के आसपास quotes भूल जाना, जैसे WHERE city = Patna, ताकि Patna को एक column name की तरह पढ़ा जाए।
  2. एक date को 2024-05-14 के बजाय '14/05/2024' जैसे किसी और format में लिखना।
  3. IS NULL के बजाय = NULL इस्तेमाल करना, जो कभी match नहीं करता।
🔒

Chapter Quiz — Complete all 8 topics to unlock

0/8 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.