advanced query formulation with sql week 10 quiz jaymond huynh tim nguyen

7
Advanced Query Formulation with SQL Week 10 Quiz Jaymond Huynh Tim Nguyen

Upload: blaise-mcbride

Post on 24-Dec-2015

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Advanced Query Formulation with SQL Week 10 Quiz Jaymond Huynh Tim Nguyen

Advanced Query Formulation with SQLWeek 10 QuizJaymond HuynhTim Nguyen

Page 2: Advanced Query Formulation with SQL Week 10 Quiz Jaymond Huynh Tim Nguyen

Question 1Which type of join should be used to include no-matching tuples from both

tables in the results?

Answer: D. A Full-Outer Join should be used to include no-matching tuples from both tables.

Page 3: Advanced Query Formulation with SQL Week 10 Quiz Jaymond Huynh Tim Nguyen

Question 2Which clauses the SELECT statement can have nested queries:

Answer: D. All of the above

Nested queries can appear in FROM, WHERE, and HAVING clauses. A nested query typically appears as part of a condition in the WHERE and HAVING clauses. However, nested queries can also be used in the FROM clause.

Page 4: Advanced Query Formulation with SQL Week 10 Quiz Jaymond Huynh Tim Nguyen

Question 3Which relational operation is very difficult to represent in SQL without nested

queries

Answer: C. Division

Sql has no direct relational division operator. The only way to get around this is the have nested queries.

Page 5: Advanced Query Formulation with SQL Week 10 Quiz Jaymond Huynh Tim Nguyen

Question 4Type II nested queries are not used for join problems because:

Answer: A. Repeated executions make them inefficient for this purpose

A Type II nested query executes one time for each row in the outer query.

Page 6: Advanced Query Formulation with SQL Week 10 Quiz Jaymond Huynh Tim Nguyen

Question 5How many rows are there in the “student” table, if “select count(name) from

student where gpa > 3” returns the number M and “select count(*) from student where gpa <= 3” returns the number N:

Answer: B. >=M+N

gpa > 3 will return the exclusive gpa”s without 3 and eh gpa <=3 will include 3 and all other gpas lower than 3. However, count(name) will only includes values that are not NULL. Not including NULL values will not show the number of rows, but the number of rows that are not NULL.

Page 7: Advanced Query Formulation with SQL Week 10 Quiz Jaymond Huynh Tim Nguyen

Question 6Explain a situation when a full outer join is useful

A full outer join can be useful to see relations between all entities.For instance, using a full outer join on two table allows the DBA to see

relations between the two tables.