The Following Steps May Be Helpful in Formulating the Query for the Problem

Total Page:16

File Type:pdf, Size:1020Kb

The Following Steps May Be Helpful in Formulating the Query for the Problem

[QueryID:18]Give all pizzas that originate from the same country as the 'siciliano' pizza. The following steps may be helpful in formulating the query for the problem: Two ways to solve this problem:

Option 1: using a subquery

1. Mapping the data items required to the column names in the DB pizza name  pizza

2. Interpret the row selection condition  Pizza that originates from the same country as the ‘siciliano’ pizza  country = the country of the siciliano pizza and pizza <> siciliano

Note: “The country of origin of the ‘siciliano’ pizza” can be obtained by a subquery, which produces the country of origin of the ‘siciliano’ pizza. In order to form a logical expression using the subquery, use “=” to link the subquery as country = (subquery)

i. Mapping the data items required to the column names in the DB country of origin  country

ii. Interpret the row selection condition  Siciliano pizza  pizza = siciliano

iii. Identify the table(s) needed, which contains all the data items used in 1) and 2) menu table

iv. Group result or individual result No aggregate function is used  individual result, Group By is not needed.

v. Using the template: SELECT FROM WHERE

3. Identify the table(s) needed, which contains all the data items used in 1) and 2) menu table 4. Group result or individual result No aggregate function is used  individual result, Group By is not needed.

5. Using the template: SELECT FROM WHERE

©H.Y Lu 2008 Option 2: -- using join

Consider two copies of the menu table, the first copy (m1) is for the selection pool of pizzas and the second one (m2) is for the siciliano pizza m2.pizza = siciliano

1. Mapping the data items required to the column names in the DB pizza name  pizza

2. Interpret the row selection condition  Pizza that originates from the same country as the ‘siciliano’ pizza  joining the two copies of the menu table based on the equality of country, and set row selection condition as m1.pizza <> siciliano and m2.pizza = siciliano

3. Identify the table(s) needed, which contains all the data items used in 1) and 2) menu m1 table and menu m2 table

4. How to join these two copies of menu table

Joining condition— m1.country = m2.country

Joining styles – in FROM, menu m1 join menu m2 on m1.country = m2.country or -- in FROM, menu m1, menu m2 and in WHERE, m1.country = m2.country

5. Group result or individual result No aggregate function is used  individual result, Group By is not needed.

6. Using the template: SELECT FROM WHERE

©H.Y Lu 2008

Recommended publications