• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/24

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

24 Cards in this Set

  • Front
  • Back

Creating a Table

CREATE TABLE mytable


(


column_name1 data_type(size),


column_name2 data_type(size),


column_name3 data_type(size)


);

Creating a new row



INSERT INTO friends (id, name, birthday)


VALUES (1, 'Jane Doe', 'May 19th, 1993');

Updating data

UPDATE friends


SET name = "Jane Smith"


WHERE name = "Jane Doe";

Adding a new column

ALTER TABLE friends ADD COLUMN email TEXT;

Deleting a row

DELETE FROM friends WHERE id = 1;




or




DELETE FROM friends WHERE name = 'Billy Joe';

What is Querying?

To retrieve data from a database.

What is the SELECT DISTINCT command/clause?

Example:


SELECT DISTINCT genre FROM movies;




This will show all the genre types that have been added in that column.




SELECT DISTINCT is used to return unique values in the result set. It filters out all duplicate values.




SELECT DISTINCT specifies that the statement is going to be a query that returns unique values in the specified column(s)

I want to know only what movies have an 8+ rating in the movies table under the rating column.




How do you show me this?

By using the WHERE clause and the > sign.




SELECT * FROM movies WHERE rating > 8;

What is the LIKE command/clause?

LIKE is a special operator used with the WHERE clause to search for a specific pattern in a column.




SELECT * FROM moviesWHERE name LIKE 'Se_en';




The _ means you can substitute any individual character here without breaking the pattern.

When is the % wildcard used?

When doing a search with LIKE




SELECT * FROM movies


WHERE name LIKE 'A%';




A% matches all movies with names that begin with "A"




%a matches all movies that end with "a"

Why use two % wildcards?




'%man%'

SELECT * FROM movies WHERE name LIKE '%man%';




You can use % both before and after a pattern. Here, any movie that contains the word "man" in its name will be returned in the result set

is the LIKE clause case sensitive?

NO

What is the BETWEEN clause?

The BETWEEN operator is used to filter the result set within a certain range. The values can be numbers, text or dates.




SELECT * FROM movies


WHERE year BETWEEN 1990 AND 2000;




The following will search through all the dates and only return movies that were published between the years 1990 and 2000!

How do I narrow down a search to 2 columns?

By using the AND clause.




Example:


SELECT * FROM moviesWHERE year BETWEEN 1990 AND 2000AND genre = 'comedy';

How do you get both the result of comedy movies and horror movies?

By using the OR clause




Example:


SELECT * FROM movies WHERE genre = 'horror' OR genre = 'comedy';

How do you sort the results of your Query?

You can sort the results of your query using ORDER BY. Sorting the results often makes the data more useful and easier to analyze.





What is the DESC clause used for?

DESC is used with ORDER BY to sort the results in descending order (high to low or Z-A).




Example:


SELECT * FROM moviesORDER BY imdb_rating DESC;




Sorts ratings from highest to lowest.

What is the ASC clause used for?

ASC is the opposite of DESC.




ASC is used with ORDER BY to sort the results in ascending order (low to high or A-Z).




SELECT * FROM moviesORDER BY imdb_rating ASCLIMIT 3;

When do you use the LIMIT clause?

LIMIT is a clause that lets you specify the maximum number of rows the result set will have




Example:


SELECT * FROM movies ORDER BY imdb_rating ASC LIMIT 3;

What is the correct syntax to filter cities by temperatures less than 35?

SELECT * FROM cities WHERE temperature > 35;

What is ORDER BY?

A clause that sorts the result set by a particular column either alphabetically or numerically.

What will this do?




SELECT * FROM sports WHERE name LIKE '%ball';

It matches all sports that end with "ball".

What is LIMIT?

A clause that lets you specify the maximum number of rows the result set will have.

Explain what Aggregate Functions are.

Aggregate Functions compute a single result from a set of input values. For instance, when we need the sum or average of a particular column, we can use aggregate functions to quickly compute it for us. We will be learning about different aggregate functions in this lesson.