Free ADC Data Retrieval & Query Techniques Questions and Answers — Questions and Answers
Question 1: What is the primary function of a SELECT statement in SQL?
- Modify existing data.
- Delete records.
- Create new tables.
- Retrieve data from one or more tables. (Correct answer)
Correct answer: Retrieve data from one or more tables.
The `SELECT` statement is the fundamental command in SQL used for querying and retrieving data from a database. It allows users to specify which columns and rows they want to view from one or more tables. Essentially, it's how you extract information stored within the database to display or use.
Question 2: Which clause is used to filter records in a SQL query?
- FROM
- GROUP BY
- WHERE (Correct answer)
- ORDER BY
Correct answer: WHERE
The `WHERE` clause in SQL is specifically used to filter records based on a specified condition. It allows you to retrieve only the rows that meet certain criteria, making your query results more precise and relevant. This is essential for narrowing down large datasets to find particular information.
Question 3: What does the JOIN operation accomplish in SQL?
- Removes duplicated data.
- Backs up the database.
- Combines data from multiple tables based on a common field. (Correct answer)
- Creates a new table.
Correct answer: Combines data from multiple tables based on a common field.
The `JOIN` operation in SQL is used to combine rows from two or more tables based on a common field between them. This allows you to retrieve a unified result set that contains data from all joined tables. It is crucial for working with relational databases where data is distributed across multiple interconnected tables.
Question 4: How can you sort data in ascending or descending order in SQL?
- GROUP BY
- SORT
- ORDER BY (Correct answer)
- FILTER
Correct answer: ORDER BY
The `ORDER BY` clause in SQL is used to sort the result set of a query. You can specify one or more columns to sort by, and choose between ascending (`ASC`) or descending (`DESC`) order. This helps in presenting data in a structured and easily understandable manner, making it easier to analyze.
Question 5: What is the result of using the DISTINCT keyword in a query?
- Sorts results alphabetically.
- Removes NULL values.
- Removes duplicate rows. (Correct answer)
- Creates table indexes.
Correct answer: Removes duplicate rows.
The `DISTINCT` keyword is used with the `SELECT` statement to eliminate duplicate rows from the result set. When applied, it ensures that each row returned is unique based on the values in the selected columns. This is particularly useful for obtaining a list of unique values or entries within a dataset.
Question 6: Which SQL function returns the number of records in a result set?
- SUM()
- TOTAL()
- COUNT() (Correct answer)
- ADD()
Correct answer: COUNT()
The `COUNT()` aggregate function in SQL is used to return the number of rows that match a specified criterion. It can count all rows, or only non-NULL values in a specific column, providing a quick way to determine the size of a result set or the number of entries in a particular category. It's a fundamental function for data aggregation.
Question 7: Which keyword is used to rename a column or table in the result set?
- ALIAS
- RENAME
- AS (Correct answer)
- MODIFY
Correct answer: AS
The `AS` keyword in SQL is used to assign a temporary name, or alias, to a column or a table in the result set of a query. This makes column headers more readable and can simplify complex queries, especially when dealing with joins or aggregate functions. The alias only exists for the duration of that specific query.
Question 8: How do you retrieve records that satisfy at least one of multiple conditions?
- AND
- BETWEEN
- NOT
- OR (Correct answer)
Correct answer: OR
The `OR` logical operator in SQL is used in the `WHERE` clause to combine multiple conditions. It retrieves records where at least one of the specified conditions is true. This allows for broader filtering, including rows that satisfy any of the given criteria, making queries more flexible.
Question 9: What does the LIKE operator do in a SQL query?
- Compares numeric ranges.
- Searches for a pattern in text. (Correct answer)
- Limits results to the first 10 rows.
- Updates column values.
Correct answer: Searches for a pattern in text.
The `LIKE` operator in SQL is used in the `WHERE` clause to search for a specified pattern within a text column. It is often used with wildcard characters, such as `%` (for any sequence of characters) and `_` (for any single character), to perform flexible string matching. This is invaluable for finding data that partially matches a given string.
What is the primary function of a SELECT statement in SQL?