Learning Mysql



Download 4.24 Mb.
View original pdf
Page125/366
Date04.08.2023
Size4.24 Mb.
#61806
1   ...   121   122   123   124   125   126   127   128   ...   366
Learning MySQL
140 | Chapter 5:
Basic SQL

combination of its album_id and the primary key of its owning entity, which is artist_id
You should now feel comfortable about choosing a database, listing its tables, and retrieving all of the data from a table using the
SELECT
statement. To practice, you might want to experiment with the university or flight databases you loaded in Chapter in Loading the Sample Databases Remember that you can use the SHOW TABLES
state- ment to find out the table names in these databases.
Choosing Columns
You’ve so far used the wildcard character to retrieve all columns in a table. If you don’t want to display all the columns, it’s easy to be more specific by listing the columns you want, in the order you want them, separated by commas. For example, if you wantonly the artist_name column from the artist table, you’d type:
mysql> SELECT artist_name FROM artist;
+---------------------------+
| artist_name |
+---------------------------+
| New Order |
| Nick Cave & The Bad Seeds |
| Miles Davis |
| The Rolling Stones |
| The Stone Roses |
| Kylie Minogue |
+---------------------------+
6 rows inset sec)
If you want both the artist_name and the artist_id
, in that order, you’d use:
mysql> SELECT artist_name,artist_id FROM artist;
+---------------------------+-----------+
| artist_name | artist_id |
+---------------------------+-----------+
| New Order | 1 |
| Nick Cave & The Bad Seeds | 2 |
| Miles Davis | 3 |
| The Rolling Stones | 4 |
| The Stone Roses | 5 |
| Kylie Minogue | 6 |
+---------------------------+-----------+
6 rows inset sec)
You can even list columns more than once:
mysql> SELECT artist_id, artist_id FROM artist;
+-----------+-----------+
| artist_id | artist_id |
+-----------+-----------+
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |

Download 4.24 Mb.

Share with your friends:
1   ...   121   122   123   124   125   126   127   128   ...   366




The database is protected by copyright ©ininet.org 2024
send message

    Main page