आइए पहले एक टेबल बनाएं -
mysql> create table DemoTable ( StudentId int, StudentName varchar(20), StudentSubject varchar(20) ); Query OK, 0 rows affected (0.62 sec)
इंसर्ट कमांड का उपयोग करके टेबल में कुछ रिकॉर्ड डालें -
mysql> insert into DemoTable values(10,'Chris','MongoDB'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values(11,'David','MySQL'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values(12,'Bob','Java'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(10,'Carol','MySQL'); Query OK, 1 row affected (0.51 sec) mysql> insert into DemoTable values(10,'Chris','MongoDB'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values(14,'David','MySQL'); Query OK, 1 row affected (0.12 sec)
चयन कथन का उपयोग करके तालिका से सभी रिकॉर्ड प्रदर्शित करें -
Mysql> select *from DemoTable;
यह निम्नलिखित आउटपुट देगा -
+-----------+-------------+----------------+ | StudentId | StudentName | StudentSubject | +-----------+-------------+----------------+ | 10 | Chris | MongoDB | | 11 | David | MySQL | | 12 | Bob | Java | | 10 | Carol | MySQL | | 10 | Chris | MongoDB | | 14 | David | MySQL | +-----------+-------------+----------------+ 6 rows in set (0.00 sec)
AND OR -
. का उपयोग करके चयन करने के लिए क्वेरी निम्नलिखित हैmysql> select *from DemoTable where StudentName='David' and StudentSubject='MySQL' OR StudentId=11;
यह निम्नलिखित आउटपुट देगा -
+-----------+-------------+----------------+ | StudentId | StudentName | StudentSubject | +-----------+-------------+----------------+ | 11 | David | MySQL | | 14 | David | MySQL | +-----------+-------------+----------------+ 2 rows in set (0.00 sec)