SQL (pronounced sequal) is a language used for retrieving data from a database. There’s no hard and fast, universal standard of this language, but over the years, most database vendors have supported very similar variants. If you learn SQL from one major database vendor, you won’t have much trouble applying your knowledge to another database.
How do you use SQL?
Consider the following database table and let’s assume the name of the table is “People”:
FirstName | LastName | Age |
John | Smith | 30 |
Mary | Jackson | 24 |
James | Martin | 36 |
John | Adams | 72 |
If you wanted to retrieve all of the records (all 4 of them) from that table, you’d write a SQL query like this:
1: SELECT
2: FirstName,
3: LastName,
4: Age
5: FROM
6: People
7:
This tells the database which columns to retrieve data from and which table to retrieve it from. The result would be:
FirstName | LastName | Age |
John | Smith | 30 |
Mary | Jackson | 24 |
James | Martin | 36 |
John | Adams | 72 |
Now, suppose you just want to retrieve all people who’s first name is “John”:
1: SELECT
2: FirstName,
3: LastName,
4: Age
5: FROM
6: People
7: WHERE
8: FirstName = 'John'
The “Where” clause stipulates that you only want records from the table whose value in the FirstName is ‘John’. This results in the following:
FirstName | LastName | Age |
John | Smith | 30 |
John | Adams | 72 |
There’s no limit to how complex a query you can write. It’s not uncommon to have a query that’s hundreds of lines long, retrieving data from multiple tables in the database.
Any program that writes or reads data to or from a database, almost certainly does so with SQL queries.