SQL Word
SQL Word
DISTINCT
Sometimes atable contains a column that has duplicate values,
and you may find yourself in a situtaion where you only want to
list the unique/distinct value.
e.g
Challenges on DISTINCT
SOLUtion
PROBLEM 3
or
SELECT and WHERE are the most fundamental SQL states and
you will find yourself using them often!
=
>
<
>=
<=
<> or !=
Logical Operators
AND
OR
NOT
EXAMPLE
What is the email for the customer with the name Nancy
Thomas?
SOLUTION
Challenges 2
SOLUTION
Challenge 3
Can you get the phone number for the customer who lives at
'259 Ipoh Drive' ?
SOLUTION
Basic syntax
Example
LIMIT
Challenge Task
BETWEEN
The BETWEEN operator can also be used with dtaes. Note that
you need to format dates in the ISO 8601 standard format,
which is YYYY-MM-DD
EXAMPLE
SELECT * FROM payment
WHERE amount BETWEEN 8 AND 9:
IN
Query Example
Percent %
Matches any sequence of characters
Underscore _
Matches any single character
Example
SELECT * FROM customer
WHERE first_name LIKE 'J%' AND last_name LIKE 'S%'
2 How many actors have a first name that start with the letter
P?
SELECT COUNT(DISTINCT(district))
FROM address;
4 Retrieve the list of name for those distinct district from the
previous question.
SELECT DISTINCT(district)
FROM address;