Learning Mysql


The SELECT Statement and Basic Querying Techniques | 157



Download 4.24 Mb.
View original pdf
Page142/366
Date04.08.2023
Size4.24 Mb.
#61806
1   ...   138   139   140   141   142   143   144   145   ...   366
Learning MySQL
The SELECT Statement and Basic Querying Techniques | 157


| 2 | Nick Cave & The Bad Seeds |
| 3 | Miles Davis |
| 4 | The Rolling Stones |
| 5 | The Stone Roses |
| 6 | Kylie Minogue |
+-----------+---------------------------+
6 rows inset sec)
and the album table:
mysql> SELECT * FROM album;
+-----------+----------+------------------------------------------+
| artist_id | album_id | album_name |
+-----------+----------+------------------------------------------+
| 2 | 1 | Let Love In |
| 1 | 1 | Retro - John McCready FAN |
| 1 | 2 | Substance (Disc 2) |
| 1 | 3 | Retro - Miranda Sawyer POP |
| 1 | 4 | Retro - New Order / Bobby Gillespie LIVE |
| 3 | 1 | Live Around The World |
| 3 | 2 | In A Silent Way |
| 1 | 5 | Power, Corruption & Lies |
| 4 | 1 | Exile On Main Street |
| 1 | 6 | Substance 1987 (Disc 1) |
| 5 | 1 | Second Coming |
| 6 | 1 | Light Years |
| 1 | 7 | Brotherhood |
+-----------+----------+------------------------------------------+
13 rows inset sec)
In response to our query, MySQL finds the artist_name and album_name value pairs that have the same artist_id values. For each artist_id in the artist table (lets use 1 as an example artist_id | artist_name |
+-----------+---------------------------+
| 1 | New Order the server finds all the entries in the album table that have this value of artist_id
:
+-----------+----------+------------------------------------------+
| artist_id | album_id | album_name |
+-----------+----------+------------------------------------------+
| 1 | 1 | Retro - John McCready FAN |
| 1 | 2 | Substance (Disc 2) |
| 1 | 3 | Retro - Miranda Sawyer POP |
| 1 | 4 | Retro - New Order / Bobby Gillespie LIVE |
| 1 | 5 | Power, Corruption & Lies |
| 1 | 6 | Substance 1987 (Disc 1) |
| 1 | 7 | Brotherhood It can then form anew temporary table from these two sets:

Download 4.24 Mb.

Share with your friends:
1   ...   138   139   140   141   142   143   144   145   ...   366




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

    Main page