Sql 2 Flashcards

(4 cards)

1
Q

What does GROUP BY do in SQL?

A

The SQL GROUP BY clause is used to arrange identical data into groups. It is often used with aggregate functions like COUNT, SUM, AVG, etc., to perform operations on each group.

This clause helps in summarizing data and is essential for generating reports and insights from datasets.

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

What is the difference between WHERE and HAVING?

A

WHERE filters individual rows before aggregation. HAVING filters groups of rows after aggregation.

WHERE is often used in conjunction with SELECT statements to refine data retrieval, while HAVING is typically paired with GROUP BY to filter aggregated results. Understanding the distinction between these clauses is crucial for effective SQL query writing.

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

What does a LEFT JOIN return that an INNER JOIN doesn’t?

A

Rows from the left table that have no corresponding match in the right table.

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

What is the purpose of an index in a database?

A

An index in a database is a data structure that improves the speed of data retrieval operations on a database table at the cost of additional space and maintenance overhead.

Indexes are used to quickly locate and access the data in a database, similar to an index in a book, which helps in finding information without scanning every page.

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