हम अपने परिणाम सेट में रिकॉर्ड्स को सॉर्ट करने के लिए MySQL ORDER BY क्लॉज का उपयोग कर सकते हैं। . विचारों के साथ ग्रुप बाय क्लॉज को समझने के लिए हम निम्नलिखित डेटा वाले आधार तालिका 'Student_info' का उपयोग करके 'जानकारी' नाम का एक दृश्य बना रहे हैं -
mysql> Select * from Student_info; +------+---------+------------+------------+ | id | Name | Address | Subject | +------+---------+------------+------------+ | 101 | YashPal | Amritsar | History | | 105 | Gaurav | Chandigarh | Literature | | 125 | Raman | Shimla | Computers | | 130 | Ram | Jhansi | Computers | | 132 | Shyam | Chandigarh | Economics | | 133 | Mohan | Delhi | Computers | +------+---------+------------+------------+ 6 rows in set (0.00 sec)
सिंटैक्स
Create or Replace View view_name AS Select_statements FROM table ORDER BY expression [ASC|DESC]बनाएं या बदलें
उदाहरण
mysql> Create or Replace View Info AS select ID, Name, Address , Subject FROM Student_info ORDER BY Name ASC; Query OK, 0 rows affected (0.11 sec) mysql> Select * from info; +------+---------+------------+------------+ | ID | Name | Address | Subject | +------+---------+------------+------------+ | 105 | Gaurav | Chandigarh | Literature | | 133 | Mohan | Delhi | Computers | | 130 | Ram | Jhansi | Computers | | 125 | Raman | Shimla | Computers | | 132 | Shyam | Chandigarh | Economics | | 101 | YashPal | Amritsar | History | +------+---------+------------+------------+ 6 rows in set (0.00 sec) mysql> Create or Replace View Info AS select ID, Name, Address , Subject FROM Student_info ORDER BY Name DESC; Query OK, 0 rows affected (0.10 sec) mysql> Select * from info; +------+---------+------------+------------+ | ID | Name | Address | Subject | +------+---------+------------+------------+ | 101 | YashPal | Amritsar | History | | 132 | Shyam | Chandigarh | Economics | | 125 | Raman | Shimla | Computers | | 130 | Ram | Jhansi | Computers | | 133 | Mohan | Delhi | Computers | | 105 | Gaurav | Chandigarh | Literature | +------+---------+------------+------------+ 6 rows in set (0.00 sec)