Snippets / SQL / WHERE

WHERE

By Marcelo Fernandes Aug 10, 2017

Standard Comparison Operators:
Operator Description
< Less Than
<= Less than or Equal to
= Equal to
>= Greater than or Equal to
> Greater than
<> NOT Equal to

SELECT town, lname, fname FROM customer WHERE town = 'Bingham';

town | lname | fname
--------+--------+---------
Bingham | Stones | Richard
Bingham | Stones | Ann
Bingham | Jones  | Dave



SELECT title, fname, lname, town FROM customer
  WHERE title <> 'Mr' AND (town = 'Bingham' OR town = 'Nicetown');

title | fname | lname | town
-------+-------+---------+----------
 Miss | Alex | Matthew | Nicetown
 Mrs  | Ann  | Stones  | Bingham


SELECT customer_id, town, lname FROM customer
 WHERE customer_id BETWEEN 5 AND 9;

customer_id | town | lname
-------------+----------+---------
 5 | Oahenham | Cozens
 6 | Nicetown | Matthew
 7 | Bingham  | Stones
 8 | Bingham  | Stones
 9 | Histon   | Hickman


Notes