Podcast
Questions and Answers
What does SQL stand for?
What does SQL stand for?
Structured Query Language
Which of these clauses is required in a SELECT statement?
Which of these clauses is required in a SELECT statement?
SQL clauses are case-sensitive.
SQL clauses are case-sensitive.
False
What is the purpose of the *
wildcard in a SELECT statement?
What is the purpose of the *
wildcard in a SELECT statement?
Signup and view all the answers
Which clause is used to filter rows based on specific criteria?
Which clause is used to filter rows based on specific criteria?
Signup and view all the answers
How do you specify a column in a SELECT statement when it has a unique name across multiple tables?
How do you specify a column in a SELECT statement when it has a unique name across multiple tables?
Signup and view all the answers
What is the purpose of the ORDER BY clause?
What is the purpose of the ORDER BY clause?
Signup and view all the answers
What is the difference between ASC and DESC in the ORDER BY clause?
What is the difference between ASC and DESC in the ORDER BY clause?
Signup and view all the answers
The NOT operator can only be used with the WHERE clause.
The NOT operator can only be used with the WHERE clause.
Signup and view all the answers
What is the purpose of the SELECT DISTINCT clause?
What is the purpose of the SELECT DISTINCT clause?
Signup and view all the answers
What is an alias, and when is it useful in SQL?
What is an alias, and when is it useful in SQL?
Signup and view all the answers
Which character is commonly used as a wildcard in MySQL LIKE statements?
Which character is commonly used as a wildcard in MySQL LIKE statements?
Signup and view all the answers
Aliases in SELECT only impact how the result is viewed and do not affect other parts of the query.
Aliases in SELECT only impact how the result is viewed and do not affect other parts of the query.
Signup and view all the answers
Study Notes
SQL Lecture Notes I
- SQL is a standardized computer language used to query, alter, and define relational databases. It uses declarative statements.
- SQL queries are constructed using a
SELECT
statement, followed by clauses in this order:-
SELECT DISTINCT
(optional) -
FROM
(required) -
WHERE
(optional) -
GROUP BY
(optional) -
HAVING
(optional) -
ORDER BY
(optional) -
;
(semicolon to end the statement - required)
-
- Example data table: Employee table with fields like
EmployeeID
,FirstName
,LastName
,Building
,Department
,HireDate
,Salary
, andJobRating
.
Wildcards
-
SELECT * FROM Employee;
— retrieves all columns and rows from theEmployee
table. -
*
is a wildcard that represents all columns.
Calculated Fields
- Calculations can be performed within the
SELECT
statement. For example,Quantity * UnitPrice
creates a new column of calculated values. - Dates can also be manipulated arithmetically in queries.
- The
AS
clause allows assigning names to calculated fields. (e.g.,AS new_column_name
).
Sorting Rows (ORDER BY
)
-
ORDER BY
is used to sort data in a specific order. -
ASC
sorts data in ascending order (alphabetical, smallest to largest). -
DESC
sorts data in descending order (reversed alphabetical, largest to smallest). - Field sorting is left to right. (e.g., order by department first then by job rating next).
Filtering rows (WHERE
)
-
WHERE
is used to filter records based on specified criteria. - Common operators include:
-
=
(equal) -
<>
or!=
(not equal) -
>, <, >=, <=
(greater than, less than, greater than or equal to, less than or equal to) -
BETWEEN
(between a specific range of values) -
IN
(is contained within a list of values) -
IS NULL
(checks for empty fields) -
LIKE
(pattern matching) - uses*
(zero or more characters) or?
(single character)
-
- Dates are often written using the
#
symbol in Ms Access.
Combining Logical Operators (AND
, OR
, NOT
)
-
AND
: Both conditions must be true. -
OR
: Either condition can be true. -
NOT
: Inverts the condition.
Aliases (SQL AS
Clause)
- Aliases provide short names for tables or columns in the
FROM
andSELECT
clauses. - Aliases are especially helpful with long table or column names to improve readability and maintainability.
Removing Duplicates (SELECT DISTINCT
)
-
SELECT DISTINCT
used in a query will remove duplicate rows with the specified column, returning distinct values only.
Date Formats (Ms Access vs. MySQL)
- Ms Access uses the format
#MM/DD/YYYY#
for dates. - MySQL uses single quotes
'YYYY-MM-DD'
for dates.
Special Characters in Table/Column Names SQL
- In some database systems, use square brackets (
[]
) when working with table/column names containing spaces or special characters in SQL queries.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
Explore the foundational concepts of SQL in this quiz. Learn how to construct queries using the SELECT statement and understand the use of wildcards and calculated fields. This quiz will help reinforce your knowledge of SQL syntax and its applications in relational databases.