W3. SQL Between Flashcards

1
Q

Q: What does the SQL BETWEEN operator do?

A

A: It selects values within a specified range, including the start and end values.

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

Q: Write a query to select all products with a price between 10 and 20.

A

SELECT * FROM Products
WHERE Price BETWEEN 10 AND 20;

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

Q: What is the syntax for the BETWEEN operator in SQL?

A

SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;

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

Q: How do you select values outside a range using BETWEEN?

A

A: Use NOT BETWEEN, e.g., WHERE Price NOT BETWEEN 10 AND 20.

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

Q: Write a query to select all products with a price outside the range 10 to 20.

A

SELECT * FROM Products
WHERE Price NOT BETWEEN 10 AND 20;

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

Q: Can BETWEEN be combined with IN in SQL?

A

A: Yes, you can add IN to further filter values within the specified range.

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

Q: Write a query to select products with a price between 10 and 20 and a CategoryID of 1, 2, or 3.

A

SELECT * FROM Products
WHERE Price BETWEEN 10 AND 20
AND CategoryID IN (1,2,3);

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

Q: How can BETWEEN be used with text values?

A

A: It can select records in alphabetical order within a specified range of text values.

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

Q: Write a query to select products with ProductName alphabetically between “Carnarvon Tigers” and “Mozzarella di Giovanni”.

A

SELECT * FROM Products
WHERE ProductName BETWEEN ‘Carnarvon Tigers’ AND ‘Mozzarella di Giovanni’
ORDER BY ProductName;

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

Q: How do you exclude text values within a range using BETWEEN?

A

A: Use NOT BETWEEN with text values, e.g., WHERE ProductName NOT BETWEEN ‘Carnarvon Tigers’ AND ‘Mozzarella di Giovanni’.

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

Q: Write a query to select products with ProductName not between “Carnarvon Tigers” and “Mozzarella di Giovanni”.

A

SELECT * FROM Products
WHERE ProductName NOT BETWEEN ‘Carnarvon Tigers’ AND ‘Mozzarella di Giovanni’
ORDER BY ProductName;

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

Q: Can BETWEEN be used with dates?

A

A: Yes, it can select dates within a specified range, including start and end dates.

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

Q: Write a query to select all orders with OrderDate between ‘1996-07-01’ and ‘1996-07-31’.

A

SELECT * FROM Orders
WHERE OrderDate BETWEEN ‘1996-07-01’ AND ‘1996-07-31’;

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