Which of the following statements are correct? A. The HAVING CLAUSE is an optional clause which tells Oracle to group rows based on distinct values that exist for specified columns. B. Unions can be used in subqueries. C. The intersect clause outputs only rows produced by both the queries intersected. D. The statement containing a subquery is called a parent statement. E. If a select statement is defined as a subquery, the innermost select statement gets executed first. Choose the correct answer from the options given below:
This question asks to identify the correct statements regarding SQL clauses and subqueries. Let's analyze each statement to determine their validity.
Statement A claims the $HAVING CLAUSE$ is optional and groups rows based on distinct values. This is incorrect. The $GROUP BY$ clause is used to group rows based on specified columns. The $HAVING$ clause, which is optional, is used to filter these groups based on a condition after the grouping has occurred, not to perform the grouping itself.
Statement B states that unions can be used in subqueries. According to the provided correct answer, this statement is considered incorrect in the context of this question. While $UNION$ operators are commonly used to combine results from multiple queries, which can include subqueries, its usage might be restricted or nuanced in certain specific scenarios not detailed here, leading to its classification as incorrect for this question.
Statement C asserts that the $INTERSECT$ clause outputs only rows produced by both queries intersected. This is correct. The $INTERSECT$ operator returns only the distinct rows that appear in the result sets of both queries involved in the operation.
Statement D identifies the statement containing a subquery as a parent statement. This is correct. The main query or the outer query that includes a subquery is referred to as the parent statement or outer query.
Statement E explains that if a $SELECT$ statement is defined as a subquery, the innermost $SELECT$ statement gets executed first. This is correct. In nested subqueries, the query execution proceeds from the innermost subquery outwards, with the results of inner queries being used by the outer queries.
Based on the analysis, statements C, D, and E are correct. Statement A is incorrect because the $HAVING$ clause filters groups, it does not perform grouping. Statement B is considered incorrect based on the context implied by the provided answer.
Therefore, the correct option includes statements C, D, and E only.
Consider a table Employee(EmpID, TeamID), where the column EmpID (ID of an employee) is the primary key. The column TeamID denotes the team ID of the team of which the employee is a member. TeamID is a NOT NULL column.
We want to display the size of the team (denoted as TeamSize) in which each employee is a member by using SQL. As an example, the desired output for the given Employee table is also shown in tabular form.
Which of the following is/are correct?
Employee
| EmpID | TeamID |
|---|---|
| 1 | 8 |
| 2 | 8 |
| 3 | 8 |
| 4 | 7 |
| 5 | 7 |
| 6 | 9 |
Output
| EmpID | TeamSize |
|---|---|
| 1 | 3 |
| 2 | 3 |
| 3 | 3 |
| 4 | 2 |
| 5 | 2 |
| 6 | 1 |
Let Account be a relation as shown.
Account
| AccNo | Balance |
|---|---|
| A1 | 5000 |
| A2 | 5000 |
| A3 | 10000 |
| A4 | 15000 |
| A5 | 18000 |
Consider the given SQL query.
SELECT AccNo FROM Account AS A
WHERE (SELECT COUNT(*) FROM Account AS B
WHERE A.Balance < B.Balance) >= (SELECT COUNT(*)
FROM Account AS C WHERE A.Balance > C.Balance)
The number of rows returned by the SQL query is __________ . (Answer in integer)
Consider the following two tables named Raider and Team in a relational database maintained by a Kabaddi league. The attribute ID in table Team references the primary key of the Raider table, ID.
| Raider | |||
| ID | Name | Raids | RaidPoints |
| 1 | Arjun | 200 | 250 |
| 2 | Ankush | 190 | 219 |
| 3 | Sunil | 150 | 200 |
| 4 | Reza | 150 | 190 |
| 5 | Pratham | 175 | 220 |
| 6 | Gopal | 193 | 215 |
| Team | ||
| City | ID | BidPoints |
| Jaipur | 2 | 200 |
| Patna | 3 | 195 |
| Hyderabad | 5 | 175 |
| Jaipur | 1 | 250 |
| Patna | 4 | 200 |
| Jaipur | 6 | 200 |
The SQL query described below is executed on this database:
SELECT *
FROM Raider, Team
WHERE Raider.ID=Team.ID AND City="Jaipur" AND
RaidPoints > 200;
The number of rows returned by this query is ________.
On a relation named Loan of a bank:
| LOAN | ||
|---|---|---|
| loan_number | branch_name | amount |
| L11 | Banjara Hills | 90000 |
| L14 | Kondapur | 50000 |
| L15 | SR Nagar | 40000 |
| L22 | SR Nagar | 25000 |
| L23 | Balanagar | 80000 |
| L25 | Kondapur | 70000 |
| L19 | SR Nagar | 65000 |
the following SQL query is executed.
SELECT L1.loan_number
FROM Loan L1
WHERE L1.amount > (SELECT MAX (L2.amount)
FROM Loan L2
WHERE L2.branch_name = 'SR Nagar');
The number of rows returned by the query is ____________ (Answer in integer)