12 Working with
Finally, we also will usually only want some of the columns, not all of them. The asterisk
means give me all columns . But usually we don't want all columns, and in many
applications, such as web pages, we could easily be receiving several requests every second. By
reducing the number of columns we ask for, we can speed up whatever web pages or other
applications are using our data.
select album, artist, purchasedate from albums where year=1979 order by
purchastedate, artist, album
SQL statements can often look a lot like English. Don't let this fool you: SQL statements
have a very strict syntax. The spelling, choice of words, and order of parts cannot usually be
modified. For example, where always comes before order by .
Text like this
Sometimes you want to find records where a value contains some piece of text. For example,
we might want to look for albums whose name begins with the word the .
select album, artist from albums where album like "the %" order by album
The keyword like is pretty much just like the equals sign for strings, except that it tells MySQL
to search inside the search string for percent symbols. Wherever it finds a percent symbol, any
text can be present in the actual records. In this case, we've told it to look for values of album
that start with the and then have any text.
We can have more than one percent in the search string. We might want to look for all of our
best of albums, but we don't know where best of appears in the album name.
select album, artist from albums where album like "%best of %"