MySQL Where Query In Hindi

📔 : MySQL 🔗

अभी तक आपने table से records को normally select किया , लेकिन क्या हो अगर हमें किसी condition के bases पर records को fetch करना हो।

Well , उसके लिए MySQL में Where statement होता है , जिसमे हम एक या एक से ज्यादा conditions को specify कर सकते हैं।

MySQL Where clause

SELECT column_list FROM table_name WHERE conditions;

conditions , आपकी एक या एक से ज्यादा conditions का combination है जो boolean value generate करता है , MySQL में AND , OR , IN , NOT IN और LIKE operators का use किया जाता है।

तो आपके द्वारा apply किया गया Boolean expression के according ही records fetch होंगे।

MySQL Where Example

Example के लिए हमारे पास एक users table है , सबसे पहले normally सभी records को fetch करके देखते हैं -

SELECT * FROM users;

Output

+----+--------+------------------+------------+---------+
| id | name   | email            | mobileno   | address |
+----+--------+------------------+------------+---------+
|  1 | Raju   | askdj@gmail.com  | 3243907889 | India   |
|  2 | Aman   | lfd@gmail.com    | 9043907889 | NULL    |
|  3 | Babloo | bsdnas@gmail.com | NULL       | US      |
|  4 | john   | Xaas@gmail.com   | 9100021321 | UAE     |
|  5 | Shaam  | Zaa@gmail.com    | 9100021334 | Russia  |
|  6 | kaam   | a@gmail.com      | 9100021326 | Turkey  |
+----+--------+------------------+------------+---------+
6 rows in set (0.001 sec)

Same table से अब हम वो records fetch करेंगे जहाँ पर address NULL है -

SELECT * FROM users WHERE address IS NULL;

Output

+----+------+---------------+------------+---------+
| id | name | email         | mobileno   | address |
+----+------+---------------+------------+---------+
|  2 | Aman | lfd@gmail.com | 9043907889 | NULL    |
+----+------+---------------+------------+---------+
1 row in set (0.001 sec)

MySQL Where with Multiple Conditions

हालाँकि अगर आप चाहे तो AND operator का use करके multiple conditions का use भी कर सकते हैं।

SELECT * FROM users WHERE mobileno='3243907889' AND address='India';

Output

+----+------+-----------------+------------+---------+
| id | name | email           | mobileno   | address |
+----+------+-----------------+------------+---------+
|  1 | Raju | askdj@gmail.com | 3243907889 | India   |
+----+------+-----------------+------------+---------+
1 row in set (0.012 sec)

ध्यान रहे , condition के लिए pass की जाने वाली value column के type के according होनी चाहिए जैसे कि string , date और time को single या double quotes के अंदर हो। हाँ integer value को आप directly compare करा सकते हैं।

MySQL OR

अब अगर आपको optional conditions pass करनी हैं तो OR का use कर सकते हैं।

SELECT * FROM users WHERE mobileno='9100021321' OR address='India';

Output

+----+------+-----------------+------------+---------+
| id | name | email           | mobileno   | address |
+----+------+-----------------+------------+---------+
|  1 | Raju | askdj@gmail.com | 3243907889 | India   |
|  4 | john | Xaas@gmail.com  | 9100021321 | UAE     |
+----+------+-----------------+------------+---------+
2 rows in set (0.001 sec)

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! My name is Rahul Kumar Rajput. I'm a back end web developer and founder of learnhindituts.com. I live in Uttar Pradesh (UP), India and I love to talk about programming as well as writing technical tutorials and tips that can help to others.

Get connected with me. :) LinkedIn Twitter Instagram Facebook

b2eprogrammers