Learning SQL: Part 2: SELECT

Learning SQL

Structured Query Language (SQL) is a declarative programming language used for accessing data storied in relational databases. It appears in or is a core part of many common software packages like MySQL, PostgreSQL, Microsoft SQL Server, and Oracle Database.


In SQL, there are four common operations: SELECT, INSERT, UPDATE, and DELETE. Each of these corresponds in order to a primary action in relation to data: getting, adding, changing, and removing.

SELECT

Accessing data from a relation database uses the keyword SELECT

Table Name: People
IDName
1Dan
2Chad

As explained in the last part, data is stored in tables composed of rows and columns. To use a SELECT statement, the first selection is from what columns to get data.

Certain Columns

For example, to get data from the “ID” and “Name” columns, a SELECT statement would start with the following:

SELECT 'ID', 'Name'

The single quotations around the column names let SQL know these are the exact names to find. As column names are case sensitive, this is important.

Column names are also separated by commas. For each column wanted, it would be listed by its name in quotations and with a comma between more than one of them.

 All Columns

Because the operation of getting data for all columns in a row is so common, there is a special character for it, *.

SELECT *

The asterisk signals to SQL that all columns should be returned for the data.

FROM

A SELECT statement proceeds from what columns to get to from where to get it. As data is stored in tables, and a database may have possibly millions of tables, an individual name is important.

The FROM keyword is used to signal from which table the data should be retrieved.

SELECT * FROM 'People'

Like the column names, table names are put into quotations to signal to find that exact table from within the database.

Quotations and Keywords

Depending on the software used with SQL, it may not use quotations around column and table names. Some allow for column and table names to appear as lowercase alongside the uppercase keywords. Nearly always, though, the keywords themselves appear as all-uppercase letters regardless of how the column and table names themselves appear.