Structured Query Language (SQL)
is a universal query language that can be use on all relational databases to query the data
Imagine that you have a music database containing all music
You might want to know all the artists who have covered The Beatles song Yesterday
SELECT artist_name, albulm_name, track_time, cover_art, mp3_track (Chooses the fields to display)
FROM music_table (Tells the computer which Table those fields are in)
WHERE song_title = "Yesterday" (Restricts the search criteria to only those records with a field value meeting the criteria)
ORDER BY artist_name ASC (Store the results in a temporary table and put in order of artist name A-Z - ASC= Ascending)
You can also query information from multiple tables
SELECT user_name, user_status, artist_name, albulm_name, track_time, cover_art, mp3_track (Chooses the fields to display)
FROM music_table,
user_table (Tells the computer which Tables those fields are in)
WHERE song_title = "Yesterday" (Restricts the search criteria to only those records with a field value meeting the criteria)
AND user_table.song_title = music table.song title (This joins / links the info in the 2 tables along the PK -> FK Relationship)
AND user_status = "online" (Also, only find me users who are currently online)
AND download_speed > 12 (Also, only find me users with a download speed of more than 12 Mbps)
ORDER BY download_speed DESC (Store the results in a temporary table and put in order of speed - DESC= Descending)
Are similar SQL based statements used to Manipulate the data
3 Main functons replace the SELECT Key word;
INSERT, UPDATE and DELETE
INSERT "Rubbish version"
INTO music_table.my_rating
FROM music_table,
WHERE artist_name = "Wurzels"
AND song_title = "Yesterday"
UPDATE music_table.my_rating = "Really nice"
FROM music_table,
WHERE artist_name = "Simon & Garfunkel"
AND song_title = "Yesterday"
DELETE * (Means All or Everything)
FROM music_table,
WHERE song_title = "Agadoo"