SQL Foundations Flashcards

(41 cards)

1
Q

What does SQL stand for?

A

Structured Query Language

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

What is a database?

A

An organized collection of data stored and accessed electronically

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

What SQL command is used to retrieve data?

A

SELECT

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

What SQL keyword is used to remove duplicate values?

A

DISTINCT

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

How do you select all columns from a table named employees?

A

SELECT * FROM employees;

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

What SQL clause filters rows based on a condition?

A

WHERE

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

How do you retrieve employees with a salary greater than 50000?

A

SELECT * FROM employees WHERE salary > 50000;

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

What is the purpose of the ORDER BY clause?

A

To sort the results by one or more columns

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

How do you sort results by name in descending order?

A

ORDER BY name DESC

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

What is the default sort order for ORDER BY?

A

Ascending (ASC)

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

What clause is used to group rows that have the same values?

A

GROUP BY

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

How do you find the number of employees in each department?

A

SELECT department

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

What function calculates the number of rows?

A

COUNT()

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

What function returns the average value of a column?

A

AVG()

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

What function returns the largest value?

A

MAX()

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

What function returns the smallest value?

A

MIN()

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

What function returns the sum of values in a column?

18
Q

What SQL clause filters groups created by GROUP BY?

19
Q

What is the difference between WHERE and HAVING?

A

WHERE filters rows before grouping; HAVING filters groups after grouping

20
Q

What SQL statement is used to insert data?

21
Q

How do you insert a row into a table?

A

INSERT INTO table_name (column1

22
Q

What statement modifies existing data?

23
Q

How do you update the salary of an employee with ID 3?

A

UPDATE employees SET salary = new_value WHERE id = 3;

24
Q

What command deletes rows from a table?

25
How do you delete all employees in department 10?
DELETE FROM employees WHERE department = 10;
26
How do you delete all records from a table but keep its structure?
DELETE FROM table_name;
27
How do you remove a table and its structure?
DROP TABLE table_name;
28
What command creates a new table?
CREATE TABLE
29
What SQL clause defines the data type and constraints of a column?
CREATE TABLE column definitions
30
What is a primary key?
A column or set of columns that uniquely identifies each row in a table
31
How do you define a primary key in SQL?
CREATE TABLE example (id INT PRIMARY KEY
32
What is a foreign key?
A column that refers to the primary key in another table
33
How do you join two tables?
Using JOIN with a matching condition
34
What does INNER JOIN do?
Returns only rows with matching keys in both tables
35
What does LEFT JOIN do?
Returns all rows from the left table and matching rows from the right table
36
What does RIGHT JOIN do?
Returns all rows from the right table and matching rows from the left table
37
What does FULL OUTER JOIN do?
Returns all rows from both tables with NULLs for missing matches
38
What does NULL mean in SQL?
A missing or unknown value
39
How do you check for NULL values?
Use IS NULL or IS NOT NULL
40
How do you rename a column in the result?
Use AS: SELECT name AS employee_name FROM employees;
41
What clause limits the number of returned rows?
LIMIT