Retrieving data from a single table Flashcards

1
Q

True or False

SQL is case sensitive?

A

False

SQL is not case sensitive but keywords are usually CAPITALIZED.

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

USE

A

to select what database to query and must be terminated ;

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

SELECT

A

which columns to query or * for all columns

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

FROM

A

what table to query

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

MYSQL how to execute a high-lighted sub query (Windows)

A

shift + ctrl + enter

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

WHERE

A

used to filter the data on a conditional basis

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

True or False

This SQL query is in the correct order of operations?

USE

SELECT

FROM

WHERE

ORDER BY

A

True

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

ORDER BY

A

determines sort order ascending is the default

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

How do you make a comment in SQL

A

– this is a comment in SQL crtl + /

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

True or False

in SQL the FROM, WHERE, and ORDER BY clauses are optional?

A

True

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

What does this code produce?

USE

SELECT 1, 2

A

creates two columns 1 and 2

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

True or False

The order doesn’t matter in SQL?

A

False

order matters when querying a database

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

True or False

White space is ignored in SQL?

A

True

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

This code does what?

SELECT
last_name,
first_name,
points,
points + 10
FROM customers

A

selects columns last_name, first_name, and points columns from customers table and adds 10 points to the points column values then creates a column points + 10 to hold those values.

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

How do you create an alias in SQL

A

AS

FROM customers c

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

How would you change the order of operation in an expression?

A

with parathesis (points + 10) * 100

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

True or False

It’s a good idea to use an alias on SQL arithmetic expressions?

A

True

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

In SQL this “discount factor” is seen as a

A

string

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

SELECT DISTINCT does what?

A

removes or ignores duplicated values

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

What is the WHERE clause doing in this query?

  • *SELECT** *
  • *FROM** Customers
  • *WHERE** points > 3000
A

filtering customers whose points are greater than 3000

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

What are the SQL comparison operators?

A

> greater than

>= greater than or equal

< less than

<= less than or equal

= equal

!=, <> not equal

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

What is the WHERE clause doing in this query?

SELECT *

FROM Customers

WHERE state = ‘VA’

A

filtering customers by the state of ‘VA’

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

What is the WHERE clause doing in this query?

  • *SELECT** *
  • *FROM** customers
  • *WHERE** state = ! ‘VA’
A

filtering customers that are NOT in the state of ‘VA’

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

What is the WHERE clause doing in this query?

  • *SELECT** *
  • *FROM** customers
  • *WHERE** birth_date > ‘1990-01-01’
A

filtering customer whose birth date is greater than 01-01-1990

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
When comparing multiple conditions in SQL what's needed?
AND, OR, NOT operators
26
How many conditions does this SQL query possess? ## Footnote * *SELECT** \* * *FROM** Customers * *WHERE** birth\_date \> '1990-01-01' **AND** points \> 1000
there are two conditions (see the WHERE clause)
27
True or False In SQL the **AND** operator is always executed first as a first-order operator?
True
28
In SQL the NOT clause does what? ## Footnote * *SELECT** \* * *FROM** Customers * *WHERE NOT** birth\_date \> '1990-01-01' **OR** points \> 1000
negates a condition \> negates to \< **OR** negates to **AND** \> negates to \<
29
In SQL arithmetic expressions are?
simple calculations performed within a query ## Footnote * *SELECT** \* * *FROM** order\_items * *WHERE** order\_id = 6 **AND** (quantity \* unit\_price \> 30)
30
Why can't you do this in SQL? ## Footnote **WHERE** state = 'VA' **OR**'GA' **OR**'FL'?
the conditions are boolean values and **OR**'GA' **OR**'FL' are string values
31
How would you refactor this query? ## Footnote * *SELECT** \* * *FROM** Customers * *WHERE** state = 'VA' **OR** state = 'GA' **OR** state = 'FL'
* *SELECT** \* * *FROM** Customers * *WHERE** state **IN** ('VA', 'GA', 'FL') similiar to the python membership operator IN
32
What is this SQL query doing? ## Footnote * *SELECT** \* * *FROM** Customers * *WHERE** state **NOT IN** ('VA', 'FL', 'GA')
selecting all records from the Customers table and filtering out states VA, GA, and FL
33
Refactor this code ## Footnote * *SELECT** \* * *FROM** customers * *WHERE** points \>= 1000 **AND** points \<= 3000
* *SELECT** \* * *FROM** customers * *WHERE** points **BETWEEN** 1000 **AND** 3000
34
What type of data type is the birth\_date column? ## Footnote * *SELECT** \* * *FROM** customers * *WHERE** birth\_date **BETWEEN**'1990-01-01' **AND**'2000-01-01'
string
35
This query is returning what? ## Footnote * *SELECT** \* * *FROM** customers * *WHERE** last\_name **LIKE**'%y'
all the last names from the customer's table that end in a y
36
This query is returning what? ## Footnote * *SELECT** \* * *FROM** customers * *WHERE** last\_name **LIKE**'%y%'
all customers where the last name has a letter y in it
37
In MySQL following the **LIKE** statement what does '-' represent in a string?
a single character
38
what is any number of characters in MySql regex?
%
39
what is a represents a single character?
\_
40
What is this query returning? ## Footnote * *SELECT** \* * *FROM** customers * *WHERE** phone **NOT LIKE**'%9'
all customers whose phone numbers that do not end in 9
41
What MySQL statement is used for searching string values?
**REGEXP** regular expression
42
True or False ## Footnote This: **WHERE** last\_name **LIKE**'%field%' is comparable to this: **WHERE** last\_name **REGEXP**'field'
True
43
This ^ represents what in a MySQL **REGEXP**
the beginning of a string ## Footnote '^waters'
44
This $ represents what in a MySQL **REGEXP**
the end of a string ## Footnote 'field$' would return Brush**field**.
45
This | represents what in a MySQL **REGEXP**
a separator to perform multiple string searches simultaneously ## Footnote **WHERE** last\_name **REGEXP**'field | mac | rose'
46
True or False ## Footnote This is 'legal' in MySQL * *SELECT** \* * *FROM** customers * *WHERE** last\_name **REGEXP**'field | mac | rose'
False no spacing allowed between 'field|mac|rose'
47
What is this query returning? ## Footnote * *SELECT** \* * *FROM** customers * *WHERE** last\_name **REGEXP**'[gim]e'
all customers whose last name ends with e but have a g, i, or m that precedes the e in it. *ge, ie, me*
48
True or False ## Footnote you can use a range of values in a MySQL REGEXP much like: **WHERE** last\_name **REGEXP**'[a-h]e'
True
49
List some MySQL REGEXP?
**^** beginning **$** end **|** logical or (called a pipe) **[abcd]** **[a-f]** range
50
This query is returning what? ## Footnote * *SELECT** \* * *FROM** customers * *WHERE** first\_name **REGEXP**'elka|ambur'
all customers whose first name are Elka or Ambur
51
This query is returning what? ## Footnote * *SELECT** \* * *FROM** customers * *WHERE** last\_name **REGEXP**'ey$|on$'
all customers whose last name ends in ey or on.
52
This query is returning what? ## Footnote * *SELECT** \* * *FROM** customers * *WHERE** last\_name **REGEXP** ‘^my|se’
all customers whose last name starts with my or contains se.
53
This query is returning what? ## Footnote * *SELECT** \* * *FROM** customers * *WHERE** last\_name **REGEXP**'b[ru]'
all customers whose last name has a b followed by r or u
54
This query is returning what? ## Footnote * *SELECT** \* * *FROM** customers * *WHERE** phone **IS NULL**
all the customers whose phones values are missing (null)
55
What is this query returning? ## Footnote * *SELECT** \* * *FROM** orders * *WHERE** shipped\_date **IS NULL**
all orders that haven't shipped
56
True or False the **ORDER BY** clause changes a table's default (primary key) sorting order
True by ascending order unless **DESC** clause is used.
57
True or False This query is legal in MySQL * *SELECT** first\_name, last\_name * *FROM** customers * *ORDER BY** birth\_date
True ordering by a column not in the selection query!
58
True or False Sorting data by columns positions is a good practice? * *SELECT** first\_name, last\_name * *FROM** customers * *ORDER** **BY** 1, 2
False if another column is added to the table, changing the order, you could be screwing yourself!
59
This query is returning what? ## Footnote * *SELECT** \* * *FROM** customers * *ORDER BY** points **DESC** * *LIMIT** 3
the top three customers in desc order
60
True or False the **LIMIT** clause should be the last line in a query if used.
True limits the # of records to return