SELECT WHERE Pt 1 and Pt 2

SELECT and WHERE are the most fundamental SQL statements

These statements will be used often

WHERE allows you to specify conditions on columns for the rows to be returned

Syntax example:

SELECT column1, column2

FROM table

WHERE conditions;

WHERE clause appears immediately after the FROM clause of the SELECT statement

The conditions are used to filter the rows returned from the SELECT statement.

PostgreSQL provides a variety of standard operators to construct the conditions. – not just unique to PostgreSQL

Comparison Operators

Compare a column value to something.

examples:

Is the price greater than $3.00?

Is the pet’s name equal to “Sam”?

$$

$$

| Operator | Description | |—|—| | = | Equal | | > | Greater than | | < | Less than | | >= | Greater than or equal to | | <= | Less than or equal to | | <> or != | Not equal to |

Logical Operators

Allow us to combine multiple comparison operators

AND

OR

NOT

SELECT name FROM table

WHERE name = ‘David’

SELECT name, choice FROM table

WHERE name = ‘David’ AND choice = “Red”

Part 2.