Question

In: Computer Science

Using the below two SQL queries and comments below, provide explanation on why the output count...

  1. Using the below two SQL queries and comments below, provide explanation on why the output count varies and which SQL yield correct result.

(20 points)

  • Both SQLs are joining two tables
  • Both SQLs are syntactically correct
  • Query #1 returns about 19614 rows versus Query #2 returns 3550134.

Query #1:

select * from person.Address addr inner join person.StateProvince prov on addr.StateProvinceID = prov.StateProvinceID

Query #2:

select * from person.Address addr,person.StateProvince prov

Solutions

Expert Solution

SOLUTION:

QUERY 1 will yield the correct Result

EXPLANATION OF OUTPUT OF QUERY 1 :

let us take two tables 1. person. Address with two attribute one is StateProvinceID on which the inner join condition is applied and one dummy attribute 2.person.StateProvince

1. person.Address

StateProvinceID address
10001 near Bangalore
10002 Chennai
10003 Hyderabad
10004 Pune

2.person.StateProvince : Take stateProvinceID and one Dummy attribute

StateProvinceID state
10001 Andhra
10002 Telangana
10003 Gujarat

NOW APPLY THE QUERY1 GIVEN

select * from person.Address addr inner join person.StateProvince prov on addr.StateProvinceID = prov.StateProvinceID

This will join the rows of table1 to rows of the table only if the value of the stateProvinceID is matched like

OUTPUT OF THE ABOVE QUERY TO THE GIVEN DATA

1->10001 of Table 1 matched to 10001 of Table2

2->10002 of Table 1 is matched to 10002 of Table 2

3->10003 of Table 1 is matched to 10003 of Table 2

for 10004 there is no matching in Table 2 so it will not be retrieved.

No other row will be returned since there are not matchings for that rows in Table2

SO we have only 3 Rows as output

person.Address person.StateProvince Table Data

stateProvinceID address stateProvienceID state
10001 near Bangalore 10001 Andhra
10002 Chennai    10002 Telangana
10003 Hyderabad 10003 Gujarat


QUERY 2:

select * from person.Address addr,person.StateProvince prov

EXPLANATION OF OUTPUT OF QUERY 2:

This is just a cross Join where we haven't applied on with any condition

We are just doing multiplication here where rows of Table are multiplied with Table 2.

OUTPUT OF THIS STATEMENT WILL BE LIKE THIS

1-> 10001 -> It will be matched with 10001
-> It will be matched with 10002
       -> It will be matched with 10003
2-> 10002 -> It will be matched with 10001
-> It will be matched with 10002
       -> It will be matched with 10003
3-> 10003 -> It will be matched with 10001
-> It will be matched with 10002
       -> It will be matched with 10003
4-> 10004 -> It will be matched with 10001
-> It will be matched with 10002
       -> It will be matched with 10003

->Thus here we will be having N*M rows where N is Table1 Rows and M is Table 2 Rows
->This is doesn't even give us an certain output, there is no need for us to join two tables without any reason, This is
not giving any information

-> If we join two tables means that we are expecting the matching data of those two tables where we can get more details
not just like multiplying all.

OUTPUT IS LIKE THIS :

address and state of the corresponding fields will be filled with that data i am concerned about the rows i just showed the result of the stateProvinceID field of two table.

stateProvinceID address stateProvienceID state
10001 10001
10001 10002
10001 10003
10002 10001
10002 10002
10002 10003
10003 10001
10003 10002
10003 10003
10004 10001
10004 10002
10004 10003

Related Solutions

Basic SQL Use the following schema to answer the queries below using SQL DEVICE [dno, dtype,...
Basic SQL Use the following schema to answer the queries below using SQL DEVICE [dno, dtype, price] PROVIDER [pno, pname, web] SERVICE [dno, pno, servicedate] SERVICE.dno references DEVICE.dno SERVICE.pno references PROVIDER.pno bold is underline. a) Find the dno for the most expensive device b) Find all providers that have the work fast in the name c) Find the number of different device types (dtype) d) Give all details of devices with price more than $400
a) Write down the SQL Statement for the below Queries b) Supply sample tale output c)...
a) Write down the SQL Statement for the below Queries b) Supply sample tale output c) the database Used is the University Schema downloaded at lecture 1. Write a query to display the name for those Students who gets more Tot_Cred than the Student whose ID is 55739. 2. Write a query to display the name salary, department name, instructor id for those instructors who works in the same department as the instructor works whose id is 83821. 3. Write...
Write the following SQL queries and show the corresponding output of the DBMS: 1) Write an...
Write the following SQL queries and show the corresponding output of the DBMS: 1) Write an SQL statement to display all the information of all Nobel Laureate winners. 2) Write an SQL statement to display the string "Hello, World!". 3) Write an SQL query to display the result of the following expression: 2 * 14 +76. 4) Write an SQL statement to display the winner and category of all Laureate winners. 5) Write an SQL query to find the winner(s)...
Create the following SQL queries using the lyrics database below 1. List the first name, last...
Create the following SQL queries using the lyrics database below 1. List the first name, last name, and region of members who do not have an email. 2. List the first name, last name, and region of members who do not have an email and they either have a homephone ending with a 2 or a 3. 3. List the number of track titles that begin with the letter 's' and the average length of these tracks in seconds 4....
Using your downloaded DBMS (MS SQL Server or MySQL), write SQL queries that inserts at least...
Using your downloaded DBMS (MS SQL Server or MySQL), write SQL queries that inserts at least three rows in each table. For the On-Demand Streaming System, First, insert information for multiple users, at least three video items and insert the three different types of subscriptions (Basic, Advanced, Unlimited) into the database. Then insert at least three user subscriptions. Execute the queries and make sure they run correctly
Write SQL queries below for each of the following: List the names and cities of all...
Write SQL queries below for each of the following: List the names and cities of all customers List the different states the vendors come from (unique values only, no duplicates) Find the number of customers in California List product names and category descriptions for all products supplied by vendor Proformance List names of all employees who have sold to customer Rachel Patterson
Write the SQL queries that accomplish the following tasks using the AP Database 9. Write a...
Write the SQL queries that accomplish the following tasks using the AP Database 9. Write a select statement to show the invoicelineitemdescriptions that have the total invoicelineitemamount >1000 and the number of accountno is >2. 10. Write a select statement that returns the vendorid, paymentsum of each vendor, and the number of invoices of each vendor, where paymentsum is the sum of the paymentotal column. Return only the top ten vendors who have been paid the most and the number...
Write SQL queries for the following statements based on Employees table whose schema is given below:...
Write SQL queries for the following statements based on Employees table whose schema is given below: (Employee_ID,First_Name,Last_Name,Email,Phone_Number,Hire_Date,Job_ID,Salary, Manager_Id, Department_Id) a. Create the given table along with the following constraints: Phone_Number should not be left undefined, salary should be between 10000 and 20000, employee_id should uniquely identify rows and should not be left undefined. User-defined names should be given to constraints. b.  Display each employee’s last name, hire date and salary review date (which is the date after six months of service)....
pleade provide the output and a brief explanation of the following C++ code: double dec1 =...
pleade provide the output and a brief explanation of the following C++ code: double dec1 = 2.5; double dec1 = 3.8; double *p, *q; p = &dec1; *p = dec2 - dec1; q = p; *q = 10.0; *p = 2 * dec1 + (*q); q =&dec2; dec1 = *p + *q; cout<<dec1<<" "<<dec2<< endl; cout<<*p<<" "<<*q<< endl; The following code should output the radius of th ebase, height , volume, and surface area of a cylinder. However, it fails...
List the primary additional datatypes used in a spatial database and provide two example queries that...
List the primary additional datatypes used in a spatial database and provide two example queries that can be run against these datatypes. Explain the differences in data representation between key:value and document databases. In your answer describe the format of a JSON document, and give an example of a query in a document database
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT