An introduction to SQL
SQL, the Structured Query Language, is an almost universally used language for speaking to relational databases and gathering information from them. A database is made up of tables – grids, like the one shown in Figure 3 – and SQL is a very expressive language for gathering information from these tables. Besides the bare data tables, we can form other tables, called queries, whose values are computed from the existing tables, by writing appropriate SQL statements.
The most basic SQL keyword is SELECT, which gets information from a number of columns. So SELECT * FROM Videos; gets us the entire Videos table, while SELECT Title FROM Videos; gets us just the Titles column. We can place constraints on these queries using the WHERE keyword: for example, SELECT ID FROM Videos WHERE Title = 'Trip to the zoo'; gets us a list of IDs of videos with the given title.
Another command we use is COUNT: enclosing a query inside COUNT collapses the resulting table to its number of columns. For example, SELECT COUNT(ID) FROM Videos; will get us the number of videos in our collection.