Basic Queries Flashcards

Learn the basic functions of queries

1
Q

Queries

A

Allow us to communicate with the database by asking questions and having the result set return data relevant to the question.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

SELECT

A

Is used every time you want to query data from a database.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

FROM

A

Identifies the database schema from which data is being queried.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

AS

A

Is a keyword in SQL that allows you to rename a column or table using an alias.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Distinct

A

When used will only return unique values. It filters out duplicate values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

WHERE

A

Is a restricting statement. filters the result set to only include rows where the following condition is true.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

LIKE

A

is a special operator used with the WHERE clause to search for a specific pattern in a column. The pattern is up to the user to identify. Text conditions need ‘ ‘

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

%

A

is a wildcard character that matches zero or more missing letters in the pattern.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

A%

A

matches all that with names that begin with letter ‘A’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

%a

A

matches all that end with ‘a’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

%a%

A

any value that contains the subject will return in the result.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

BETWEEN

A

operator can be used in a WHERE clause to filter the result set within a certain range. The values can be numbers, text or dates.BETWEEN two letters is not inclusive of the 2nd letter.
BETWEEN two numbers is inclusive of the 2nd number.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

AND

A

combines the two conditions. Used in conjunction with Where.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

OR

A

operator displays a row if any condition is true.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Order By

A

Sorts the result.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Limit

A

Don’t destroy the database.

17
Q

Case

A

A statement that allows us to create different outputs (usually in the SELECT statement). It is SQL’s way of handling if-then logic.

EX:
SELECT name,
 CASE
  WHEN imdb_rating > 8 THEN 'Fantastic'
  WHEN imdb_rating > 6 THEN 'Poorly Received'
  ELSE 'Avoid at All Costs'
 END
FROM movies;

Each WHEN tests a condition and the following THEN gives us the string if the condition is true.
The ELSE gives us the string if all the above conditions are false.
The CASE statement must end with END.