7. SQL Introduction

SQL (Standard Querying Language) provides a powerful and concise way to make selections from a database. Though there are several good tutorials available (better than this one :-), a short introduction will be given here on the most important topics. To make a selection from a database, the most basic informaion you will need is what variables to select and from which table to select it from. The general syntax to do this is:

SELECT variable FROM table

Here table would be the name you used when you created the table and variable would be one the mp3wharf variables. Use a * to select all variables.Some examples would be:

SELECT * FROM main
SELECT id, artist FROM main
SELECT id, artist, songtitle, album FROM main
SELECT id, artist, songtitle, album FROM compilation1

To filter certain records, you can use the WHERE statement. The WHERE statement should be followed by some logical expression containing one of the following
=, equals
<>, equals not
<, greater than
>, less than
like, regular expression (using ? and %)

Examples would be:
SELECT * FROM main WHERE artist="Dazzling Killmen"
SELECT * FROM main WHERE artist LIKE "%Dazzling%"
SELECT * FROM main WHERE artist LIKE "%Dazzling%" AND year>1996
SELECT * FROM main WHERE artist LIKE "%Dazzling%" AND (year>1996 OR year <1985)


Next: Executing Queries |  Back to index