Meta DE Technical Screen Flashcards

(64 cards)

1
Q

What is SQL?

A

Structured Query Language is used to store, retrieve, filter, and analyze data in relational databases.

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

What is PostgreSQL?

A

An open-source relational database system that uses SQL.

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

What is a database?

A

A collection of tables that store related data.

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

What is a table?

A

A structured set of rows and columns.

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

What is a row?

A

one record

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

What is a column?

A

one attribute of the data

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

What is the basic SQL query order?

A

SELECT
FROM
WHERE
GROUP BY
HAVING
ORDER BY
LIMIT

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

What does SELECT do?

A

chooses which columns to return

SELECT name, age FROM users;

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

What does FROM do?

A

specifies the table to query

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

What does SELECT * do?

A

returns all columns

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

What does WHERE do?

A

filters rows based on conditions

WHERE age > 21

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

What are the comparison operators?

A

=, !=, <, >, <=, >=

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

What are the logical operators?

A

AND, OR, NOT

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

What does BETWEEN do?

A

WHERE age BETWEEN 18 AND 30

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

What does IN do?

A

specifies constraints
WHERE country IN (‘US’, ‘CA’)

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

What does LIKE do?

A

contains portions of strings to match

WHERE email LIKE ‘%@gmail.com’

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

What is a NULL?

A

missing or unknown value

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

Why can’t we use = NULL?

A

NULL is not equal to anything, even NULL

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

What is the correct way to check NULL?

A

WHERE column IS NULL
WHERE column IS NOT NULL

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

What is COALESCE?

A

replace NULL with a default value

ex: COALESCE(score, 0)

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

What does ORDER BY do?

A

sorts results

ex: ORDER BY created_at DESC

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

What is ASC vs DESC?

A

ascending vs descending

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

What does LIMIT do?

A

limits the number of rows returned

ex: LIMIT 10

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

What is aggregation?

A

combining multiple rows into a single value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What are some common aggregation functions?
COUNT() SUM() AVG() MIN() MAX()
26
What does COUNT(*) do?
counts all rows, including NULLs
27
What does COUNT(column) do?
counts non-NULL values
28
What does GROUP BY do?
groups rows so aggregations can be applied per group
29
What is an example of GROUP BY?
SELECT country, COUNT(*) FROM users GROUP BY country;
30
What is the rule of using GROUP BY?
ever column in SELECT must be either in GROUP BY or inside an aggregation function
31
What does HAVING do?
filters aggregated results ex: HAVING COUNT(*) > 5
32
When do you use WHERE vs HAVING?
WHERE - before aggregation HAVING - after aggregation
33
Why do joins exist?
data is split across tables to reduce duplication
34
What is an INNER JOIN?
only matching rows
35
What is an example of an INNER JOIN?
FROM orders o JOIN customers c ON o.customer_id = c.customer_id
36
What is a LEFT JOIN?
all rows from left table + matches from right
37
What is a RIGHT JOIN?
all rows from right table + matches from left
38
What is a FULL OUTER JOIN?
all rows from both tables
39
What happens when no match exists?
NULL values appear
40
What is a table alias?
a way to identify a table usually using a single letter ex: FROM users u
41
What is a column alias?
renaming a column name when performing some type of operation ex: SELECT COUNT(*) AS user_count
42
What is UNION?
combines results and removes duplicates
43
What is UNION ALL?
combines results and keeps duplicates(faster)
44
What is the requirement for UNION?
same number of columns and compatible types
45
What is a subquery?
a query inside another query
46
What is an example of a subquery?
SELECT * FROM users WHERE age > ( SELECT AVG(age) FROM users );
47
Why do we use subqueries?
when logic is easier to express step by step
48
What is a CASE?
conditional logic in SQL ex: CASE WHEN score >= 90 THEN 'High' ELSE 'Low' END
49
What is a window function?
performs calculations across rows without collapsing them
50
What does OVER() do?
defines the window
51
How is ROW_NUMBER used?
ROW_NUMBER() OVER (ORDER BY score DESC) unique ranking, no ties
52
How do we use PARTITION BY?
PARTITION BY user_id
53
How do we do string concatenation?
first_name || ' ' || last_name
54
What is a primary key?
A column (or set of columns) that uniquely identifies each row
55
What is a foreign key?
a column that references a primary key in another table
56
What is an example of performing an inner join?
SELECT * FROM orders o INNER JOIN customers c ON o.customer_id = c.customer_id;
57
What is a CROSS JOIN?
a cartesian product (every row paired with every row)
58
Why is a cross join dangerous?
it has exponential growth
59
What is the memory trick for WHERE vs HAVING?
WHERE -> rows HAVING -> groups
60
What requires GROUP BY?
any non-aggregated column in SELECT
61
What is a correlated subquery?
a subquery that references columns from the outer query
62
What is an example of a correlated subquery?
SELECT * FROM employees e WHERE salary > ( SELECT AVG(salary) FROM employees WHERE department = e.department );
63
What is RANK?
ties allowed, gaps in ranking
64
What is DENSE_RANK?
ties allowed, no gaps ex: DENSE_RANK() OVER (PARTITION BY user_id ORDER BY score DESC)