0
0
MySQLquery~5 mins

Why SELECT retrieves data in MySQL

Choose your learning style9 modes available
Introduction

The SELECT statement is used to get data from a database table. It helps you see the information stored inside.

When you want to see all the records in a table, like all customers in a store.
When you need to find specific information, like a product with a certain price.
When you want to check if some data exists before making changes.
When you want to show data on a website or report.
When you want to analyze or summarize data from a table.
Syntax
MySQL
SELECT column1, column2, ... FROM table_name;
Use * to select all columns: SELECT * FROM table_name;
You can select one or more columns separated by commas.
Examples
This gets all columns and all rows from the employees table.
MySQL
SELECT * FROM employees;
This gets only the name and age columns from every employee.
MySQL
SELECT name, age FROM employees;
This gets names of employees older than 30 years.
MySQL
SELECT name FROM employees WHERE age > 30;
Sample Program

This creates a table called fruits, adds three fruit records, and then retrieves all the data from the table.

MySQL
CREATE TABLE fruits (id INT, name VARCHAR(20), color VARCHAR(20));
INSERT INTO fruits VALUES (1, 'Apple', 'Red'), (2, 'Banana', 'Yellow'), (3, 'Grape', 'Purple');
SELECT * FROM fruits;
OutputSuccess
Important Notes

SELECT is the main way to read data from a database.

It does not change or delete data, only shows it.

You can combine SELECT with conditions to get only the data you want.

Summary

SELECT is used to get data from tables.

You can choose which columns to see.

It helps you view and analyze stored information.