NULL चेक करने के लिए IS NULL का उपयोग करें। खाली मानों के लिए, आपको खाली स्ट्रिंग से चेक करना होगा। अब एक उदाहरण देखते हैं।
पहले एक टेबल बनाते हैं:
mysql> create table DemoTable691( PlayerId int NOT NULL AUTO_INCREMENT PRIMARY KEY, PlayerName varchar(100), PlayerScore int ); Query OK, 0 rows affected (0.56 sec)
इन्सर्ट कमांड का उपयोग करके टेबल में कुछ रिकॉर्ड डालें:
mysql> insert into DemoTable691(PlayerName,PlayerScore) values('Robert',56); Query OK, 1 row affected (0.17 sec)
mysql> insert into DemoTable691(PlayerName,PlayerScore) values('David',89); Query OK, 1 row affected (0.12 sec)
mysql> insert into DemoTable691(PlayerName,PlayerScore) values('',98); Query OK, 1 row affected (0.18 sec)
mysql> insert into DemoTable691(PlayerName,PlayerScore) values(null,71); Query OK, 1 row affected (0.17 sec)
सेलेक्ट स्टेटमेंट का उपयोग करके टेबल से सभी रिकॉर्ड प्रदर्शित करें:
mysql> select *from DemoTable691;
यह निम्न आउटपुट देगा:
+----------+------------+-------------+ | PlayerId | PlayerName | PlayerScore | +----------+------------+-------------+ | 1 | Robert | 56 | | 2 | David | 89 | | 3 | | 98 | | 4 | NULL | 71 | +----------+------------+-------------+ 4 rows in set (0.00 sec)
खाली और NULL मान एक साथ प्रदर्शित करने की MySQL क्वेरी:
mysql> select *from DemoTable691 where PlayerName IS NULL OR PlayerName='';
यह निम्न आउटपुट देगा:
+----------+------------+-------------+ | PlayerId | PlayerName | PlayerScore | +----------+------------+-------------+ | 3 | | 98 | | 4 | NULL | 71 | +----------+------------+-------------+ 2 rows in set (0.00 sec)