MySQL Tutorial
The SELECT statement is used to select or retrieve the data from one or more tables.
The SELECT statement is used to retrieve all the rows from a table or as well as to retrieve only those rows that satisfy a certain condition
SELECT column1, column2, column3, ...
FROM table_name;
Here, column1, column2, column3, ... are the field names of the table you want to select data.
If you want to select all the fields available in the table, use the following syntax:
SELECT * FROM table_name;
Let's put these statements into real use.
We've a table named Students in our database that contains the following records:
ROLL_NO | NAME | SUBJECT |
---|---|---|
1 | Will | C++ |
2 | SAM | Python |
3 | Sara | HTML | 4 | Rim | Java |
5 | Micheal | SQL |
6 | Lara |
SELECT ROLL_NO, NAME FROM Students;
The above SELECT statement selects two columns(ROLL_NO and NAME) from the above Students table.
ROLL_NO | NAME |
---|---|
1 | Will |
2 | SAM |
3 | Sara | 4 | Rim |
5 | Micheal |
6 | Lara |
Now we will select all the fields available in the table.
SELECT * FROM Students;
The above SELECT statement selects all columns from the Students table.
ROLL_NO | NAME | SUBJECT |
---|---|---|
1 | Will | C++ |
2 | SAM | Python |
3 | Sara | HTML | 4 | Rim | Java |
5 | Micheal | SQL |
6 | Lara |