SQL Flashcards

1
Q

What is SQL and how is it different from languages like JavaScript?

A

Structured Query Language (SQL) is the primary way of interacting with relational databases. JS is imperative programming language and SQL is a declarative programming language

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

How do you retrieve specific columns from a database table?

A

SELECT column name and FROM table name

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

How do you filter rows based on some specific criteria?

A

select, from, and where keyword

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

What are the benefits of formatting your SQL?

A

Helps us to make the queries more readable and easy to understand.

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

What are the benefits of formatting your SQL?

A

Helps us to make the queries more readable and easy to understand.

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

What are four comparison operators that can be used in a where clause?

A

=, <, >, and !=

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

How do you limit the number of rows returned in a result set?

A

use limit keyword and the number of rows

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

How do you retrieve all columns from a database table?

A

select * from tableName

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

How do you control the sort order of a result set?

A

order by “column name” desc/asc

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

How do you add a row to a SQL table?

A

Insert into “tableName” (“columnName”)
values (‘value’)

insert into “products” (“name”, “description”, “price”, “category”)
values (‘Ostrich Pillow’, ‘Feel comfy and cozy!’, 99, ‘self care’);

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

What is a tuple?

A

a list of values

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

How do you add multiple rows to a SQL table at once?

A

values (‘value’),
(‘value’)

insert into “products” (“name”)
values (‘Ostrich Pillow’),
(‘Tater Mitts’)
returning *;

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

How do you get back the row being inserted into a table without a separate select statement?

A

by using keyword returning *;

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

How do you update rows in a database table?

A

update “tableName”
set “column/attribute” = ‘value’
where “selection” = ‘value’;

update “products”
set “price” = 100
where “productId” = 24;

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

Why is it important to include a where clause in your update statements?

A

to target specific rows so it does not update every row in the table

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

How do you delete rows from a database table?

A

delete
from “table name”
where “columnName/attribute” = ‘value’

delete
from “products”
where “productId” = 24
returning *;

16
Q

How do you accidentally delete all rows from a table?

A

delete
from “tableName”;

17
Q

What is a foreign key?

A

Column that show up in multiple tables

18
Q

How do you join two SQL tables?

A

select “tableName”.”columnName”
from “tableName”
join “tableName” using (“columnName”);

select “p”.”name” as “product”,
“p”.”category”,
“s”.”name” as “supplier”,
“s”.”state”
from “products” as “p”
join “suppliers” as “s” using (“supplierId”);

19
Q

How do you temporarily rename columns or tables in a SQL statement?

A

join “tableName” as “c” using (“customerId”)

“tableName”.”currentColumnName” as “newColumnName”

20
Q

What are some examples of aggregate functions?

A

An aggregate function performs a calculation on a set of values, and returns a single value. Ex: min(), sum(), and every(), max()

21
Q

What is the purpose of a group by clause?

A

the group the results of aggregate functions . It basically allows us to create our own collection of data within a collection of data