SQL Query Flashcards

1
Q

What is querying in SQL?

A

The process of retrieving specific data from a database.

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

What is the typical syntax structure of an SQL query?

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
3
Q

Which clause is executed last in SQL query execution?

A

The SELECT clause.

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

What is the purpose of the SELECT clause?

A

To specify which columns or expressions to retrieve.

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

What does the FROM clause do?

A

Specifies the table(s) from which to retrieve data.

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

What is the purpose of the WHERE clause?

A

To filter rows based on specified conditions.

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

What does the GROUP BY clause do?

A

Groups rows that have the same values in specified columns.

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

What does the HAVING clause do?

A

Filters groups created by GROUP BY based on conditions.

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

What is the role of ORDER BY?

A

To sort the query result set based on one or more columns.

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

What does the LIMIT clause do?

A

Restricts the number of rows returned by the query.

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

What does OFFSET do when used with LIMIT?

A

Specifies the starting point from which rows are returned.

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

Which clause is responsible for filtering rows before grouping?

A

WHERE clause.

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

Which clause filters grouped data?

A

HAVING clause.

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

Which clause determines which table data comes from?

A

FROM clause.

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

Which clause defines how many records are returned?

A

LIMIT clause.

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

If you want to find all employees in the ‘Sales’ department, what clause should you use?

A

WHERE clause.

17
Q

If you want to group sales data by region, which clause is needed?

A

GROUP BY clause.

18
Q

If you want to show only regions with total sales over $10,000, which clause is necessary?

A

HAVING clause.

19
Q

To show the top 5 highest-paid employees, what clauses might you use?

A

ORDER BY salary DESC LIMIT 5.

20
Q

What does the COUNT() function do?

A

Counts the number of rows in a specified column.

21
Q

What does SUM() function do?

A

Calculates the total sum of a column.

22
Q

What does AVG() function do?

A

Calculates the average value of a column.

23
Q

What does MIN() function do?

A

Finds the minimum value in a column.

24
Q

What does MAX() function do?

A

Finds the maximum value in a column.

25
Q

What does DISTINCT do in a SELECT query?

A

Removes duplicate rows from the result set.

26
Q

What is the purpose of AS in a SELECT query?

A

Gives an alias (temporary name) to a column or expression.

27
Q

Spot the mistake: ‘SELECT name salary FROM employees;’

A

Missing comma. Correct syntax: SELECT name, salary FROM employees;

28
Q

Spot the mistake: ‘SELECT * employees;’

A

Missing FROM clause. Correct syntax: SELECT * FROM employees;

29
Q

Spot the mistake: ‘ORDER name BY ASC;’

A

Correct syntax: ORDER BY name ASC;

30
Q

What is the correct order of clauses in an SQL SELECT query?

A

SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT.

31
Q

Which clause is conceptually executed before SELECT but written after it?

A

FROM clause.

32
Q

Does SQL execute SELECT clause first or last?

33
Q

If you write WHERE before FROM, will the query work?

A

No, SQL requires FROM before WHERE.

34
Q

What happens if you skip WHERE in a DELETE operation?

A

All rows will be affected.

35
Q

If you use HAVING without GROUP BY, what does it apply to?

A

The entire result set, treated as a single group.

36
Q

Explain in your own words the difference between WHERE and HAVING.

A

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

37
Q

Describe the purpose of ORDER BY in a query.

A

It sorts the results based on one or more columns in ascending or descending order.

38
Q

What is the difference between COUNT() and SUM()?

A

COUNT() counts rows, SUM() totals values in a numeric column.