W3. SQL Select Top Flashcards

1
Q

Q: What does the SQL SELECT TOP clause do?

A

A: It specifies the number of records to return from a query, often to improve performance on large tables.

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

Q: Write an example query to select the first 3 records from the “Customers” table using SELECT TOP.

A

SELECT TOP 3 * FROM Customers;

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

Q: Which SQL clause does MySQL use instead of SELECT TOP?

A

LIMIT

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

Q: Write a MySQL query to select the first 3 records from the “Customers” table.

A
SELECT * FROM Customers 
LIMIT 3;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Q: What clause does Oracle use to limit records?

A

A: FETCH FIRST n ROWS ONLY or ROWNUM

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

Q: Write an Oracle query to select the first 3 records from the “Customers” table.

A
SELECT * FROM Customers 
FETCH FIRST 3 ROWS ONLY;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Q: How do you select a percentage of records using SELECT TOP?

A

A: Add PERCENT after the number, e.g.,
SELECT TOP 50 PERCENT * FROM Customers;

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

Q: Write a SQL Server query to select the first 50% of records from the “Customers” table.

A

SELECT TOP 50 PERCENT * FROM Customers;

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

Q: How can you limit records with a condition (e.g., customers from Germany) using SELECT TOP?

A
SELECT TOP 3 * FROM Customers 
WHERE Country = 'Germany';
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Q: Write a MySQL query to select the first 3 customers from Germany.

A
SELECT * FROM Customers 
WHERE Country = 'Germany' 
LIMIT 3;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Q: How do you sort and limit the result set using ORDER BY with SELECT TOP?

A

A: Add ORDER BY after specifying TOP, e.g.,
SELECT TOP 3 * FROM Customers ORDER BY CustomerName DESC;

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

Q: Write a query to select the top 3 customers sorted in reverse alphabetical order by CustomerName (for MySQL).

A
SELECT * FROM Customers 
ORDER BY CustomerName DESC 
LIMIT 3;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Q: Write an Oracle query to fetch the top 3 customers sorted in reverse alphabetical order by CustomerName.

A
SELECT * FROM Customers 
ORDER BY CustomerName DESC 
FETCH FIRST 3 ROWS ONLY;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly