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

IS NULL और IS NOT NULL

NULL का मतलब है 'हमें नहीं पता', जो zero या blank से अलग है। आप इसके बारे में IS NULL से पूछते हैं, क्योंकि एक equals sign किसी mystery को compare नहीं कर सकता।
Syntax
sql
WHERE column_name IS NULL
WHERE column_name IS NOT NULL

Empty Fields ढूँढना

Databases में, NULL missing या unknown data represent करता है, zero या एक empty string नहीं। हम NULL check करने के लिए equals sign इस्तेमाल नहीं कर सकते, क्योंकि NULL कभी किसी के बराबर नहीं होता, खुद के भी नहीं। इसके बजाय, हमें इन rows ढूँढने के लिए special IS NULL operator इस्तेमाल करना ज़रूरी है।

उदाहरण: Finding Empty Fields

sql
SELECT * FROM users WHERE phone IS NULL;

Completed Fields ढूँढना

अगर आपको ऐसी rows ढूँढनी हों जहाँ किसी column में actual data हो, IS NOT NULL operator इस्तेमाल करें। यह completed fields या verified accounts identify करने के लिए perfect है, जैसे वे users जिन्होंने अपना email address confirm किया है।

उदाहरण: Finding Completed Fields

sql
SELECT * FROM users WHERE phone IS NOT NULL;

Calculations में Nulls के साथ काम करना

NULL values के साथ math करना पूरे result को NULL बना सकता है, जो चुपचाप totals और averages तोड़ देता है। हम calculation चलने से पहले NULL values को एक default number से replace करने के लिए IFNULL या COALESCE जैसे functions इस्तेमाल करते हैं।

उदाहरण: Working with Nulls in Calculations

sql
SELECT IFNULL(discount, 0) AS discount, COALESCE(discount, 0) AS discount2 FROM orders;

Equals Null काम क्यों नहीं करता

NULL के साथ normal equals sign इस्तेमाल करना एक empty result set return करता है, जो WHERE column = NULL लिखने वाले कई beginners को confuse करता है। ऐसा इसलिए क्योंकि NULL एक value नहीं है, इसलिए यह किसी के भी बराबर नहीं हो सकता, एक दूसरे NULL सहित। इसके बजाय हमेशा IS NULL इस्तेमाल करना याद रखें।

उदाहरण: Why Equals Null Does Not Work

sql
SELECT * FROM users WHERE phone = NULL; -- always returns empty
SELECT * FROM users WHERE phone IS NULL; -- correct way

Null Checks को Filters के साथ Combine करना

आप अपने WHERE clause में NULL checks को दूसरी search conditions के साथ mix कर सकते हैं, जैसे एक missing phone number वाले active users ढूँढना। हम उन्हें cleanly साथ जोड़ने के लिए AND या OR इस्तेमाल करते हैं, बिल्कुल किसी दूसरे filter condition जैसे।

उदाहरण: Combining Null Checks with Filters

sql
SELECT * FROM users WHERE is_active = 1 AND phone IS NULL;
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. WHERE phone = NULL लिखना, जो कभी match नहीं करता क्योंकि NULL को IS NULL से compare किया जाता है।
  2. एक empty string '' को NULL की तरह treat करना, जबकि वे अलग values हैं।
  3. arithmetic में एक NULL column add करना और एक number की उम्मीद करना, जबकि result NULL बन जाता है।
🔒

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.