The SELECT statement retrieves all the rows from the friends table, which has four columns: id, Name, Lastname, and Telephone. The result shows five rows, each representing a person and their corresponding information in the table.
mysql> SELECT * FROM friends;
+----+-----------+----------+-----------+
| id | Name | Lastname | Telephone |
+----+-----------+----------+-----------+
| 1 | John | Smith | 111333 |
| 2 | Anastasia | TheGreat | 555777 |
| 3 | Samantha | Fox | 456456 |
| 10 | Larry | TheFirst | 555888 |
| 11 | Bill | Gates | 444888 |
+----+-----------+----------+-----------+
5 rows in set (0.00 sec)
mysql>
The id column uniquely identifies each person, and it was set to automatically increment by 1 for each new row inserted. The Name column stores the first name of each person, the Lastname column stores their last name, and the Telephone column stores their phone number.
The rows are ordered by the value in the id column in ascending order.
mysql> SELECT Name from friends;
+-----------+
| Name |
+-----------+
| John |
| Anastasia |
| Samantha |
| Larry |
| Bill |
+-----------+
5 rows in set (0.00 sec)
mysql>
This SELECT statement retrieves data from the friends table but only for the Name column, so only the values of the Name column are displayed in the result.
The result shows five rows, each row contains the Name value of a friend from the table.
mysql> SELECT name from friends;
+-----------+
| name |
+-----------+
| John |
| Anastasia |
| Samantha |
| Larry |
| Bill |
+-----------+
5 rows in set (0.00 sec)
mysql>
In MySQL, column names are case insensitive by default, so "name" and "Name" are considered the same column in the "friends" table. When you ran the second SELECT statement using "name" in lowercase, it returned the same result as the first SELECT statement that used "Name" with an uppercase N.
mysql> SELECT NAME FROM FRIENDS;
+-----------+
| NAME |
+-----------+
| John |
| Anastasia |
| Samantha |
| Larry |
| Bill |
+-----------+
5 rows in set (0.00 sec)
mysql>
By default, table and column names are case-insensitive.
This means that whether you use upper-case or lower-case letters to refer to table or column names in your queries, MySQL will treat them the same. In the example you provided, the first query used the lower-case "Name" to select data from the "friends" table, while the second query used the upper-case "NAME".
Both queries returned the same result because MySQL is not case-sensitive in this regard.
mysql> SELECT Name, Telephone FROM friends;
+-----------+-----------+
| Name | Telephone |
+-----------+-----------+
| John | 111333 |
| Anastasia | 555777 |
| Samantha | 456456 |
| Larry | 555888 |
| Bill | 444888 |
+-----------+-----------+
5 rows in set (0.00 sec)
mysql>
This query selects two columns, Name and Telephone, from the friends table. The result will be a table with all rows in the friends table, but only with these two columns, where the column "Name" shows the name of the person and the column "Telephone" shows their phone number.
mysql> SELECT id, Name, Telephone FROM friends;
+----+-----------+-----------+
| id | Name | Telephone |
+----+-----------+-----------+
| 1 | John | 111333 |
| 2 | Anastasia | 555777 |
| 3 | Samantha | 456456 |
| 10 | Larry | 555888 |
| 11 | Bill | 444888 |
+----+-----------+-----------+
5 rows in set (0.00 sec)
mysql>
This is a sample MySQL query that selects three columns, "id", "Name", and "Telephone" from the "friends" table. The results are displayed in a tabular format with one row for each record in the table that meets the query criteria. In this case, there are five rows displayed.
The "SELECT" statement is used to retrieve data from one or more tables in a MySQL database. The "FROM" clause specifies the table or tables from which the data should be retrieved. In this case, the "friends" table is being queried.
No comments:
Post a Comment