Querying in SQL Flashcards
What is the SELECT statement, and what statement is it used with?
Basic statement that is used to retrieve data from a SQL database; used with the FROM statement.
Clause that is used to filter certain results being returned
WHERE
What are standard numerical operators (6)?
Clause: ???
=, !=, , >=
I.E.
Col_name != 4
Clause: WHERE
Number is within range of two values (inclusive)
Clause: ???
BETWEEN … AND …
I.E.
Col_name BETWEEN 1.5 AND 5
Clause: WHERE
Number is not within range of two values (inclusive)
Clause: ????
NOT BETWEEN … AND …
I.E.
Col_name NOT BETWEEN 3 AND 5
Clause: WHERE
Number exists in a list
String exists in a list
Clause: ????
IN (…)
I.E. Col_name IN (2, 4, 6) Col_name IN ("A", "B", "C")
Clause: WHERE
Number does not exist in a list
String does not exist in a list
Clause: ????
NOT IN (…)
I.E.
Col_name NOT IN (1, 2, 3)
Col_name NOT IN (“A”, “B”, “C”)
Clause: WHERE
Case sensitive exact string comparison
=
I.E.
Col_name = “abc”
Case sensitive exact string inequality comparison
!=,
I.E.
Col_name != “xyza”
Case INSENSITIVE exact string comparison
LIKE
I.E.
Col_name LIKE “fgh”
Case INSENSITIVE exact string inequality comparison
NOT LIKE
I.E.
Col_name NOT LIKE “gnhc”
Used anywhere in a string to match a sequence of zero or more characters
Used with something.
%
I.E.
Col_name LIKE “%AT%” (matches “AT”, “ATTIC”, “CAT” or even “BRATS”)
used with LIKE and NOT LIKE
Used anywhere in a string to match a single character
Used with something
_
I.E.
Col_name LIKE “AN_” (matches “AND”, but not “AN”)
used with LIKE and NOT LIKE
What is the DISTINCT clause?
With what statement is it used?
Discard rows that have a duplicate column value; SELECT statement.
What is the purpose of the ORDER BY clause?
And what is commonly used with it?
The ORDER BY clause is a way to sort results by a given column in ascending or descending order.
The LIMIT will reduce the number of rows to return, and OFFSET will specify where to begin counting the number rows from.