This set of SQL Multiple Choice Questions & Answers (MCQs) focuses on “SQL Self Join”.
1. What is a SELF JOIN?
a) It is an irregular join
b) It is used to join a table to itself
c) It is used to join a table to other tables
d) It cannot be done in SQL
View Answer
Explanation: A SELF JOIN is a regular join, but the table is joined with itself. It is used to join a table to itself as if the table were two tables.
2. Self joins are used to ________
a) Compare values in a column with other values in the same column of the same table
b) Compare values in a column with other values in the same column of the other table
c) Compare values in a column with other values in the other column of the other table
d) Compare values in a column with some given value
View Answer
Explanation: SELF JOIN is used to join or compare a table with itself. SQL self joins are used to compare values of a column with values of same or another column in the same table.
3. SELF JOIN is a keyword in SQL.
a) True
b) False
View Answer
Explanation: There is no keyword as SELF JOIN in SQL. But it is referred when a table joins with itself.
4. Which of the following is necessary for a SELF JOIN in SQL?
a) Join
b) Alias
c) Order by
d) Group by
View Answer
Explanation: We must use a table alias to distinguish the left table from the right table of the same table in a single query when we perform a SELF JOIN.
5. What is the syntax for self join?
a)
SELECT column_list FROM table1 SELF JOIN table1 WHERE condition(s);
b)
SELECT column_list FROM table1 JOIN table1 WHERE condition(s);
c)
SELECT column_list FROM table1 T SELF JOIN table1 S WHERE condition(s);
d)
SELECT column_list FROM table1 T JOIN table1 S WHERE condition(s);
Explanation: SELF JOIN is not a keyword in SQL. As we refer to the same table twice in a SELF JOIN, we have to use table aliases. Syntax of a self join is:
SELECT column_list FROM TABLE A (INNER | OUTER) JOIN TABLE B WHERE condition(s);
6. To construct a SELF JOIN, how many times the same table is selected by a SELECT statement?
a) Only once
b) Twice
c) More than two times
d) Thrice
View Answer
Explanation: To construct a self join, we select the same table twice by using the SELECT statement with an inner join or outer join clause.
Sanfoundry Global Education & Learning Series – SQL.
To practice all areas of SQL, here is complete set of 1000+ Multiple Choice Questions and Answers.
If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]