4. SQL and DML Flashcards

1
Q

What is a relational table?

A

A relational table has a unique name, is organized in rows and columns, with each row representing a unique instance of an entity type, each column having a unique name with values from the same domain, and each cell holding one value.

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

What are the two main operations in SQL for querying a table?

A

Selection retrieves specific rows using a WHERE clause, while Projection retrieves specific columns using the SELECT list.

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

What does the DISTINCT keyword do in SQL?

A

DISTINCT eliminates duplicate rows from the query result.

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

What are group functions in SQL?

A

Group functions, such as COUNT, MAX, AVG, MIN, and SUM, aggregate rows and return a single result.

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

What is the purpose of the GROUP BY clause?

A

GROUP BY groups rows based on specified columns so that aggregate functions can be applied to each group.

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

What is a column alias and why is it used?

A

A column alias renames a column in the result set, improving clarity especially when expressions are used.

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

How can expressions be used in SQL queries?

A

Expressions combine mathematical operators and functions to compute derived values in the SELECT clause.

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

How are NULL values represented and handled in SQL?

A

NULL represents missing or unknown data; functions like IFNULL can substitute values, and conditions use IS NULL or IS NOT NULL to check for NULLs.

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

How do you order query results in SQL?

A

The ORDER BY clause sorts the results by one or more columns, with options for ascending or descending order.

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

What is a join in SQL?

A

A join combines rows from two or more tables based on related columns between them.

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

What is an inner join?

A

An inner join returns rows that meet the join condition from both tables.

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

What is a natural join?

A

A natural join returns rows with matching values in columns that share the same name in both tables.

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

What is an outer join?

A

An outer join returns rows even when there is no matching row in the joined table, with missing values filled as NULL.

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

What is a self join?

A

A self join is when a table is joined with itself using aliases to distinguish the different instances.

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

What is SQL Data Manipulation Language (DML) used for?

A

SQL DML is used to query and modify data in a database, including operations like SELECT, INSERT, UPDATE, and DELETE.

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

What are the main clauses of a SELECT statement?

A

The main clauses are SELECT, FROM, WHERE, GROUP BY, HAVING, and ORDER BY.

17
Q

What is the typical processing order of a SELECT statement?

A

The processing order is FROM, WHERE, GROUP BY, HAVING, SELECT, then ORDER BY.

18
Q

How do Boolean operators function in SQL queries?

A

Boolean operators such as AND, OR, and NOT combine conditions in the WHERE clause, with NOT having the highest precedence, followed by AND and then OR, unless parentheses override the order.

19
Q

What is the difference between the WHERE and HAVING clauses?

A

WHERE filters rows before grouping, while HAVING filters groups after aggregation.

20
Q

What are common comparison operators in SQL?

A

Common operators include =, >, >=, <, <=, <> (or !=), and are used to compare values in conditions.