MySQL SELECT Statement

MySQL SELECT Statement

The SELECT statement in MySQL is used to retrieve data from one or more database tables. It is the most commonly used SQL command and forms the basis of most database queries.


๐Ÿ“Œ Basic Syntax


Or to select all columns:



๐Ÿงช Example

Suppose you have a table named students:

id name age
1 Rahul 20
2 Priya 22
3 Aman 21

Select all data:


Select specific columns:



๐ŸŽฏ Using SELECT With WHERE Clause (Filtering Data)

The WHERE keyword filters records based on a condition.



๐Ÿ”  Using SELECT With ORDER BY (Sorting Results)



๐Ÿ” Using SELECT With DISTINCT (Unique Values)


This removes duplicate values.


๐Ÿ”ข Using SELECT With LIMIT (Limit Output Count)


This returns only the first 2 rows.


๐Ÿ” Using SELECT With Aliases (Renaming Columns)


Aliases make results easier to read.


๐Ÿ”ง Using SELECT With Functions

MySQL includes built-in functions for data analysis.

Function Example
COUNT() Total count of rows
MAX() Largest value
MIN() Smallest value
SUM() Total of values
AVG() Average value

Example:



๐Ÿงฉ Combine Multiple Conditions

With AND and OR:



๐Ÿ“˜ Summary

Feature Example
Select all data SELECT * FROM table;
Select columns SELECT name, age FROM students;
Filter data SELECT * FROM students WHERE age > 20;
Sort results ORDER BY column ASC/DESC
Remove duplicates SELECT DISTINCT column;
Limit rows LIMIT number

โœ” The SELECT statement is essential for reading and analyzing database records.

CodeCapsule

Sanjit Sinha โ€” Web Developer | PHP โ€ข Laravel โ€ข CodeIgniter โ€ข MySQL โ€ข Bootstrap Founder, CodeCapsule โ€” Student projects & practical coding guides. Email: info@codecapsule.in โ€ข Website: CodeCapsule.in

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *