If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
तो पिछले topic में आपने MySQL में Insert Statement के बारे में पढ़ा और समझा , इस topic में हम देखेंगे कि किसी table से records को कैसे display / list करते हैं।
Record Insert करने के लिए हमने tutorials
database की users
table को use किया था , तो हम उसी table से records को display करेंगे।
बैसे तो किसी table से records को select करने के कई तरीके हैं लेकिन , अभी हम सबसे easy method देखेंगे , *
sign की help से हम किसी table से सभी records को fetch करते हैं।
SELECT * statement से किसी table से सभी records एक साथ fetch होते हैं।
SELECT * FROM users;
Output
+----+--------+-----------------+------------+----------------+ | id | name | email | mobileno | address | +----+--------+-----------------+------------+----------------+ | 1 | User 1 | user1@gmail.com | 3243907889 | User 1 Address | | 2 | User 2 | user2@gmail.com | 9043907889 | NULL | | 3 | User 3 | user3@gmail.com | NULL | User 3 Address | | 4 | User 4 | user4@gmail.com | 9100021321 | User 4 Address | | 5 | User 5 | user5@gmail.com | 9100021334 | User 5 Address | | 6 | User 6 | user6@gmail.com | 9100021326 | User 6 Address | +----+--------+-----------------+------------+----------------+ 6 rows in set (0.051 sec)
Output में आप देख सकते हैं कि users
table में जितने records थे सभी display हो चुके हैं।
अगर आप सिर्फ कुछ particular columns को ही select करना चाहते हैं तो , उन column name को comma separated ,
define करना पड़ेगा। जैसा कि आप नीचे दिए गए example में देख सकते हैं।
SELECT name, email FROM users;
+--------+-----------------+ | name | email | +--------+-----------------+ | User 1 | user1@gmail.com | | User 2 | user2@gmail.com | | User 3 | user3@gmail.com | | User 4 | user4@gmail.com | | User 5 | user5@gmail.com | | User 6 | user6@gmail.com | +--------+-----------------+ 6 rows in set (0.001 sec)
Table से आप records की limit भी decide कर सकते हैं कि कितने records आपको चाहिए इसके लिए LIMIT
keyword का use किया जाता है।
SELECT * FROM users LIMIT 2;
Output
+----+--------+-----------------+------------+----------------+ | id | name | email | mobileno | address | +----+--------+-----------------+------------+----------------+ | 1 | User 1 | user1@gmail.com | 3243907889 | User 1 Address | | 2 | User 2 | user2@gmail.com | 9043907889 | NULL | +----+--------+-----------------+------------+----------------+ 6 rows in set (0.051 sec)
हालाँकि आप limit
के बारे में आगे detail में पढ़ेंगे।
इसके अलावा आप SELECT
Statement के साथ ORDER BY , GROUP BY , LIMIT / SKIP etc का use भी कर सकते हैं जिन्हे आप आगे पढ़ेंगे।
अगर आपको column name का नाम change करना है , मतलब जो name आपने Table Create करते time define किया था उसे select करते time दूसरे name से भी access कर सकते हैं।
column को दूसरे name से access करने के लिए AS
keyword का use किया जाता है।
Example
SELECT name AS user_name, email AS user_email FROM users;
Output
+-----------+-----------------+ | user_name | user_email | +-----------+-----------------+ | User 1 | user1@gmail.com | | User 2 | user2@gmail.com | | User 3 | user3@gmail.com | | User 4 | user4@gmail.com | | User 5 | user5@gmail.com | | User 6 | user6@gmail.com | +-----------+-----------------+ 6 rows in set (0.039 sec)
तो I Hope, अब आपको समझ आ गया होगा कि MySQL Table से records को कैसे fetch करते हैं।
Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)
Get connected with me. :) LinkedIn Twitter Instagram Facebook