SQL Flashcards

1
Q

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

A

It’s a declarative language you only need to tell it what to do

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

by using select “column 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

by using where + condition

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

To make it more readable

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

< ,> , != , =

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

with limit (must be at the end)

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

with *

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

with order by (in ascending)
else place desc for descending

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

How do you skip lines of code?

A

With offset

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

How do you add a row to a SQL table?

A

insert into “table” (“property”, …)
values (‘value’, …)

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

What is a tuple?

A

A list of values inside ( )

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

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

A

insert into “table” (“property”, …)
values (‘value’, …),
(‘value’, …)

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

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

A

insert into “table” (“property”, …)
values (‘value’, …),
(‘value’, …)
return *

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

How do you update rows in a database table?

A

update “table”
set “target” = value
where “condition” = comparison;

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

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

A

To pin point the specific target

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

How do you delete rows from a database table?

A

delete
from “table”
where “column” = value
returning *;

17
Q

How do you accidentally delete all rows from a table?

A

delete
from “table”;

(you don’t add where)

18
Q

What is a foreign key?

A

an id/key from another table

19
Q

How do you join two SQL tables?

A

select *
from “table”
join “table2” using (“tableId”);

20
Q

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

A

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

21
Q

What are some examples of aggregate functions?

A

count( )
sum( )
total( )
avg( )
min( )
max( )

22
Q

What is the purpose of a group by clause?

A

To separate rows from groups