Learning Mysql


The SELECT Statement and Basic Querying Techniques | 141



Download 4.24 Mb.
View original pdf
Page126/366
Date04.08.2023
Size4.24 Mb.
#61806
1   ...   122   123   124   125   126   127   128   129   ...   366
Learning MySQL
The SELECT Statement and Basic Querying Techniques | 141


| 4 | 4 |
| 5 | 5 |
| 6 | 6 |
+-----------+-----------+
6 rows inset sec)
Even though this appears pointless, it can be useful when combined with aliases in more advanced queries, as we show in Chapter You can specify databases, tables, and column names in a
SELECT
statement. This allows you to avoid the
USE
command and work with any database and table directly with
SELECT
; it also helps resolve ambiguities, as we show later in Joining Two Tables.”
Consider an example suppose you want to retrieve the album_name column from the album table in the music database. You can do this with the following command:
mysql> SELECT album_name FROM music.album;
+------------------------------------------+
| album_name |
+------------------------------------------+
| Let Love In |
| Retro - John McCready FAN |
| Substance (Disc 2) |
| Retro - Miranda Sawyer POP |
| Retro - New Order / Bobby Gillespie LIVE |
| Live Around The World |
| In A Silent Way |
| Power, Corruption & Lies |
| Exile On Main Street |
| Substance 1987 (Disc 1) |
| Second Coming |
| Light Years |
| Brotherhood |
+------------------------------------------+
13 rows inset sec)
The music.album component after the
FROM
keyword specifies the music database and its album table. There’s no need to enter USE music before running this query. This syntax can also be used with other SQL statements, including the UPDATE, DELETE, INSERT, and
SHOW
statements we discuss later in this chapter.
Choosing Rows with the WHERE Clause
This section introduces the
WHERE
clause and explains how to use the Boolean operators to write expressions. You’ll see these inmost
SELECT
statements, and often in other statements such as
UPDATE
and DELETE we’ll show you examples later in this chapter.
WHERE basics
The
WHERE
clause is a powerful tool that allows you to choose which rows are returned from a
SELECT
statement. You use it to return rows that match a condition, such as having a column value that exactly matches a string, a number greater or less than a

Download 4.24 Mb.

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




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

    Main page