Learning SQL
Using SQL
Mastering 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.
To help retrieve, organize, and sort data, there are a large number of keywords connected to using SELECT statements. Many of these are also used with UPDATE and DELETE to help work on only those rows and columns needed.
WHERE
The use of a SELECT statement can potentially return a large number or results. To help reduce this to only the most needed, the WHERE keyword can be used to impose a conditional clause on the statement.
SELECT Name FROM People WHERE Name = 'Dan'
Like in other programming languages, there are many ways to write conditional clauses that compare values.
Operator | Description |
---|---|
= | Equal |
<>, != | Not equal. |
> | Greater than |
< | Less than |
>= | Greater than or equal |
<= | Less than or equal |
BY
The keyword BY is most frequently combined with two other keywords, ORDER and GROUP.
ORDER BY
With the case of ORDER BY, the results of a SELECT statement are organized according to one or more column name.
SELECT Name FROM People ORDER BY ID
GROUP BY
To help organize results into “groups”, there is the GROUP BY keyword combination.
SELECT Name FROM People GROUP BY ID
AND
The AND keyword is used to combine multiple conditional clauses with a SELECT statement.
SELECT Name FROM People WHERE Name = 'Dan' AND ID = '1'