Review the diagram.
Data manipulation language operations are:
- SELECT
- INSERT
- UPDATE
SELECT A1, A2, A3..., An
FROM T1, T2, T3,..., Tn
WHERE condition
Comparison Operator | Description |
---|---|
= | Equal |
<=> | Equal (MySql, safe to compare NULL values) |
<> | Not Equal |
!= | Not Equal |
> | Greater Than |
>= | Greater Than or Equal |
< | Less Than |
<= | Less Than or Equal |
BETWEEN | Within a range (inclusive) |
NOT | Negates a condition |
IS NULL | NULL value |
IS NOT NULL | Non-NULL value |
LIKE | Pattern matching with % and _ |
IN ( ) | Matches a value in a list |
EXISTS | Condition is met if subquery returns at least one row |
SELECT title, rating, length
FROM film
WHERE length > 100;
SELECT title, `length` FROM film
WHERE `length` BETWEEN 100 AND 120;
SELECT city, district
FROM address, city
WHERE address.city_id = city.city_id;
SELECT [DISTINCT] country, city
FROM address, city, country
WHERE address.city_id = city.city_id
AND city.country_id = country.country_id;
SELECT title, name
FROM film, `language`
WHERE film.language_id = language.language_id
AND film.`length` > 100 AND language.name = 'English'
SELECT title, category_id
FROM film, film_category, category
WHERE film.film_id = film_category.film_id
AND film_category.category_id = category.category_id
SELECT title, special_features, rental_rate, name
FROM film, film_category, category
WHERE film.film_id = film_category.film_id
AND film_category.category_id = category.category_id
ORDER BY rental_rate DESC
SELECT title, special_features, rental_rate, name
FROM film, film_category, category
WHERE film.film_id = film_category.film_id
AND film_category.category_id = category.category_id
ORDER BY rental_rate DESC, special_features ASC
SELECT * FROM actor
LIMIT 10;
Wildcard | Explanation |
---|---|
% | Allows you to match any string of any length (including zero length) |
_ | Allows you to match on a single character |
SELECT *
FROM film
WHERE special_features LIKE '%Trailers%'
When searching for characters _ %, they have to be escaped with \ (default escape character)
SELECT * FROM address
WHERE address LIKE '%\_%';
SELECT title, description, rental_rate * 150 AS "In Pesos"
FROM film