</>
Skip to content
MySQL lessons (15/48)

MySQL — Select

Basic SELECT

-- Select all columns
SELECT * FROM users;

-- Select specific columns
SELECT name, email FROM users;

SELECT with WHERE

SELECT * FROM users WHERE age > 18;
SELECT * FROM users WHERE name = 'John';
SELECT * FROM users WHERE email LIKE '%@gmail.com';

SELECT with ORDER BY

SELECT * FROM users ORDER BY name ASC;
SELECT * FROM users ORDER BY age DESC;

SELECT with LIMIT

SELECT * FROM users LIMIT 10;
SELECT * FROM users LIMIT 10 OFFSET 5;

SELECT Examples

-- Select with aliases
SELECT name AS 'User Name', email AS 'Email Address'
FROM users;

-- Select distinct values
SELECT DISTINCT category FROM products;

-- Select with functions
SELECT name, UPPER(email) FROM users;
SELECT name, YEAR(created_at) FROM users;

-- Select with multiple conditions
SELECT * FROM products
WHERE price > 100 AND stock > 0
ORDER BY price ASC
LIMIT 10;

Mini Practice

Write MySQL code that:

  1. Selects all data
  2. Selects specific columns
  3. Uses WHERE clause
  4. Orders results

Up Next

Next: Learn about WHERE clause.

Related Topics

Frequently Asked Questions about Select

What is Select in MySQL?

Select is a fundamental concept in MySQL. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Select?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Select.

Why is Select important in MySQL?

Select is essential for MySQL development. Understanding this concept will help you write better code and solve real-world problems more effectively.