आइए पहले एक टेबल बनाएं -
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(20) ); Query OK, 0 rows affected (1.23 sec)
इंसर्ट कमांड का उपयोग करके टेबल में कुछ रिकॉर्ड डालें -
mysql> insert into DemoTable(StudentName) values('John'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable(StudentName) values('Carol'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(StudentName) values('David'); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable(StudentName) values('Bob'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(StudentName) values('Chris'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(StudentName) values('Robert'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(StudentName) values('Adam'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(StudentName) values('Mike'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(StudentName) values('Sam'); Query OK, 1 row affected (0.16 sec)
चयन कथन का उपयोग करके तालिका से सभी रिकॉर्ड प्रदर्शित करें -
mysql> select *from DemoTable;
आउटपुट
+----+-------------+ | Id | StudentName | +----+-------------+ | 1 | John | | 2 | Carol | | 3 | David | | 4 | Bob | | 5 | Chris | | 6 | Robert | | 7 | Adam | | 8 | Mike | | 9 | Sam | +----+-------------+ 9 rows in set (0.00 sec)
यहाँ विशिष्ट पंक्तियों का चयन करने के लिए क्वेरी है MySQL -
mysql> select *from DemoTable ORDER BY Id DESC LIMIT 4 OFFSET 2;
आउटपुट
+----+-------------+ | Id | StudentName | +----+-------------+ | 7 | Adam | | 6 | Robert | | 5 | Chris | | 4 | Bob | +----+-------------+ 4 rows in set (0.00 sec)