Select statement
199
To read one or multiple records from a table you use select
statement.
select * from `user`;
+----+----------+-----------------------+--------------+---------------------+
| id | name | email | password | registered |
+----+----------+-----------------------+--------------+---------------------+
| 1 | Silvia | silvia@gmail.com | silvia1990 | 2019-05-12 00:00:00 |
| 2 | Angel | angel@springville.com | 1PzIjSWmj3 | 2020-02-07 00:00:00 |
| 3 | Carolina | carolina@studio.org | funnybunny95 | 2020-06-12 00:00:00 |
| 4 | Michael | michael@mail.com | 84738257342 | 2020-09-24 00:00:00 |
+----+----------+-----------------------+--------------+---------------------+
4 rows in set (0.00 sec)
The example above is the most simple data selection from a table. It return every row and every column. Instead of that, you can specify some particular columns to select:
select `name`, `email` from `user`;
+----------+-----------------------+
| name | email |
+----------+-----------------------+
| Silvia | silvia@gmail.com |
| Angel | angel@springville.com |
| Carolina | carolina@studio.org |
| Michael | michael@mail.com |
+----------+-----------------------+
4 rows in set (0.00 sec)
Now we select two columns only. However, we still select all rows available. To filter some particular rows you can use where
statement:
select `name`, `email` from `user` where `id` = 1;
+--------+------------------+
| name | email |
+--------+------------------+
| Silvia | silvia@gmail.com |
+--------+------------------+
1 row in set (0.00 sec)
Now only those rows are returned which match to the given condition.
Rate this post:
Lesson 5
Lesson 7
Share this page:
Learning plan
3. Table
How to create a table — entities a database consists of
4. CRUD
Create, read, update, delete
How to create one or multiple records in a table
6. Select statement
How to query records from a table
How to update previously created data in a table
How to delete data from a table