Joins Questions and Answers

SQL Server Questions and Answers – Joins

This set of SQL Server Multiple Choice Questions & Answers (MCQs) focuses on “Joins”.

1. The following SQL is which type of join: SELECT CUSTOMER_T. CUSTOMER_ID, ORDER_T. CUSTOMER_ID, NAME, ORDER_ID FROM CUSTOMER_T,ORDER_T WHERE CUSTOMER_T. CUSTOMER_ID = ORDER_T. CUSTOMER_ID?
a) Equi-join
b) Natural join
c) Outer join
d) Cartesian join

Explanation: Equi-join links only fields with the same data entry. One table may have department id, while another should contain department id.

2. A UNION query is which of the following?
a) Combines the output from no more than two queries and must include the same number of columns
b) Combines the output from no more than two queries and does not include the same number of columns
c) Combines the output from multiple queries and must include the same number of columns
d) Combines the output from multiple queries and does not include the same number of columns

Explanation: A single UNION can combine only 2 sql query at a time.

3. Which of the following statements is true concerning subqueries?
a) Involves the use of an inner and outer query
b) Cannot return the same result as a query that is not a subquery
c) Does not start with the word SELECT
d) All of the mentioned

Explanation: A subquery, also known as an inner query or inner select, is a SELECT statement that is nested within another subquery or contained within a data manipulation language (DML) expression.

4. Which of the following is a correlated subquery?
a) Uses the result of an inner query to determine the processing of an outer query
b) Uses the result of an outer query to determine the processing of an inner query
c) Uses the result of an inner query to determine the processing of an inner query
d) Uses the result of an outer query to determine the processing of an outer query

Explanation: A correlated subquery is a phrase that refers to a certain form of SQL query in a computer database. It’s a subquery (a query nested inside another query) with a WHERE clause that uses values from the outer query.

5. How many tables may be included with a join?
a) One
b) Two
c) Three
d) All of the Mentioned

Explanation: Join can be used for more than one table. For ‘n’ tables the no of join conditions required are ‘n-1’.

6. The following SQL is which type of join: SELECT CUSTOMER_T. CUSTOMER_ID, ORDER_T. CUSTOMER_ID, NAME, ORDER_ID FROM CUSTOMER_T,ORDER_T?
a) Equi-join
b) Natural join
c) Outer join
d) Cartesian join

Explanation: The Cartesian Join is essentially the joining of one or more tables to produce the product of all the rows in the tables.

7. Which is not a type of join in T-SQL?
a) Equi-join
b) Natural join
c) Outer join
d) Cartesian join

Explanation: A NATURAL JOIN is an inner join in which the RDBMS determines the join columns based on the names of common columns. A NATURAL JOIN is implemented by some RDBMS vendors, such as Oracle, but not by SQL Server.

8. What type of join is needed when you wish to include rows that do not have matching values?
a) Equi-join
b) Natural join
c) Outer join
d) All of the Mentioned

Explanation:OUTER JOIN is the only join which shows the unmatched rows.

9. What type of join is needed when you wish to return rows that do have matching values?
a) Equi-join
b) Natural join
c) Outer join
d) All of the Mentioned

Explanation: Outer join returns the row having matching as well as non matching values.

10. Which of the following is one of the basic approaches for joining tables?
a) Subqueries
b) Union Join
c) Natural join
d) All of the Mentioned

Explanation: The SQL subquery is a SELECT query within the main SELECT statement. A subquery can be used instead of a JOIN in many circumstances.

An inner join demands that each row in the two connected tables have the same column values, and it is a typical join procedure in applications, but it is not always the best option. Inner join combines column values from two tables (A and B) depending on the join-predicate to create a new result table. To identify all pairings of rows that satisfy the join-predicate, the query compares each row of A with each row of B. Column values for each matched pair of rows of A and B are joined into a result row when the join-predicate is satisfied by matching non-NULL values.

Leave a Reply

Your email address will not be published. Required fields are marked *