Learn SQL – WHERE statement

Hi, let suppose that we only want to get points greater than 3000, so in the WHERE clause we can type this condition:

SELECT *
FROM customers
WHERE points > 3000;

Result: The condition will go through every row in the table and if the condition is true it will return that customer in the result. 

SQL operators 

If we want the customer that lives in Virginia:

SELECT *
FROM customers
WHERE state = 'VA';

Result: It doesn’t matter if the ‘VA’ characters are in uppercase or lowercase, you will have the same result.

If you want all the customers outside of the state of Virginia: 

We can use ‘not equal‘ operator

SELECT *
FROM customers
WHERE state != 'VA';

OR 

SELECT *
FROM customers
WHERE state <> 'VA';

Result: We will have the same result

If we want to get only the customers born after January 1st. 1990:

We need to use the operator “>” then the date wrapped in single quotes for representing date values even though dates are actually not strings. But in the SQL language, we should enclose dates with quotes.

The standard date representation will be:

4 digits for the year, 2 digits for the month and 2 digits for the day. 

‘1990-01-01’ Year 1990, January month, day 1


SELECT *
FROM customers
WHERE birth_date > '1990-01-01';

Result:

Finally, get all the orders placed in year 2019:

SELECT * 
FROM orders 
WHERE order_date >= '2019-01-01'

Result:

Credits Mosh 

By Cristina Rojas.