WHERE Clause
In this page:
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
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
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
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
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
SELECT * FROM users WHERE status != 'inactive';
- text के आसपास quotes भूल जाना, जैसे
WHERE city = Patna, ताकिPatnaको एक column name की तरह पढ़ा जाए। - एक date को
2024-05-14के बजाय'14/05/2024'जैसे किसी और format में लिखना। IS NULLके बजाय= NULLइस्तेमाल करना, जो कभी match नहीं करता।
Chapter Quiz — Complete all 8 topics to unlock
0/8 topics done
Complete these topics first: