Question

1. For each query, there are one or more things to do. Some of these queries...

1. For each query, there are one or more things to do. Some of these queries use SQL constructs we haven't covered in class but that you should be able to figure out the meaning of.

a.

SELECT C.custid, C.companyname

FROM Sales.Customers AS C

LEFT OUTER JOIN Sales.Orders as O

ON C.custid = O.custid

WHERE O.orderid IS NULL

Provide the result set generated by this query.

One of the result rows should be (22, Customer DTDMN). What does this tell you about customer 22?

b.

SELECT custid, companyname

FROM Sales.Customers as C

WHERE NOT EXISTS (

  SELECT * FROM Sales.Orders as O

  WHERE O.custid = C.custid

)

Explain what the result set represents.

c.

SELECT empid

FROM HR.Employees as E

WHERE (

  SELECT COUNT(*)

  FROM Sales.Orders as O

  WHERE O.empid = E.empid

) > 90

Explain what the result set represents.

Write a query that produces the same result that uses GROUP BY and HAVING.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

a.) Left outer join basically returns everything from Customer table irrespective of the fact that wether the Orders table has related value, hence there are various null value in the resultant table.

According to query we have to return customer id and company name from the resultant table after performing left outer join.

Hence, (22, Customer DTDMN) means customer with customer id=22 has not placed any order with the company Customer DTDMN.

b.) It will give wrong answer as the inner loop will select everything from orders table and then the outer loop would not be able to exclude the instances on the basis of particular values.

C.) It has 2 loops inner loop and outer loop the value obtained from outer loop dependent on value of inner loop.

Inner loop: it will perform natural join of orders and employee table on the basis of employeId amd return the count

Outer loop: it will return all empId where the count is greator than 90.

Add a comment
Know the answer?
Add Answer to:
1. For each query, there are one or more things to do. Some of these queries...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • QUERY EXAMPLE2 SELECTfrom Employee em (Refer to query example 2 to answer questions 12- 13) 12....

    QUERY EXAMPLE2 SELECTfrom Employee em (Refer to query example 2 to answer questions 12- 13) 12. You plan to join the Location table and fear there may be some employees with no location. You want to make sure that the query returns a list of all employee What join clause would you add to the query above? records. A. LEFT JOIN Location lo ON em.LocationlD lo LocationID B. RIGHT JOIN Location lo ON em.LocationID lo.LocationlD C. INNER JOIN Location lo...

  • A(n) __________________ is a logical connection between rows in two tables where data in one table...

    A(n) __________________ is a logical connection between rows in two tables where data in one table references data in another table. The SQL ________________ statement removes a table from a database. The relational algebra "restrict" operator selects only the rows from the input table(s)  that satisfy a condition expressed in the _________________ clause. The SQL/PL ______________ command is used to re-direct the output of a script file to a text file. The ________________________ join creates a result set that includes the...

  • can someone solve these quick please and thank you! sql chapter 4 Query #1: List the...

    can someone solve these quick please and thank you! sql chapter 4 Query #1: List the company name, contact name, contact title and the phone number for customers who HAVE NOT put in an order. Use an outer join. Query #2: Create a listing displaying the employee first name, last name and the full name (First name space Last Name) of the person they report to (Supervisor). This is a self-join. If an employee does not report to anyone then...

  • QUESTION 21 Complete the table below by matching each definition with the appropriate SQL clause. -A.B.C.D.E.F.G.H.I.J.K.L.M.N....

    QUESTION 21 Complete the table below by matching each definition with the appropriate SQL clause. -A.B.C.D.E.F.G.H.I.J.K.L.M.N. A mandatory clause that is at the start of all SQL retrieval queries -A.B.C.D.E.F.G.H.I.J.K.L.M.N. A clause used to return only the values in a result table that are unique -A.B.C.D.E.F.G.H.I.J.K.L.M.N. A clause used to filter tuples according to some condition or predicate, like selection in relational algebra -A.B.C.D.E.F.G.H.I.J.K.L.M.N. A clause that is used to list the tables and any joins required in a query...

  • Please help me to solve Please, No handwriting COURSE; introduction to database Q- write a query ...

    Please help me to solve Please, No handwriting COURSE; introduction to database Q- write a query SQL by Using the info below A. Normalize the Tables (in 3NF at least) B. Create the Normalized Tables and Populate them with at least 5 Rows C. Write the Wholesale Management System requested Queries & Execute them VERY IMPORTANT Screenshots from MySQL (or any other software you use) of all the tables after queries result. - Database system for a Wholesale Management System...

  • You will develop an E-Commerce database used to maintain customers, products and sales information. You are...

    You will develop an E-Commerce database used to maintain customers, products and sales information. You are required to 1) gather and analyze requirements 2) design logical structure of the database 3) create stored procedures to develop the tables and insert the data 4) write SQL statements for data extraction and reporting. Throughout the course of this semester you have analyzed the requirements for an eCommerce database, designed and developed your database. As a class we have gone through the process...

  • What happens when you try to compile and run the following code? String query = "INSERT...

    What happens when you try to compile and run the following code? String query = "INSERT INTO Invoices (InvoiceDate InvoiceTotal) "              + "VALUES ('2/10/01', '443.55')"; Statement statement = connection.createStatement(); statement.executeUpdate(query); a. A SQLException is thrown at runtime because the executeUpdate method can’t accept a String object. b. A SQLException is thrown at runtime because the SQL statement is coded incorrectly. c. An error occurs at compile time because the SQL statement is coded incorrectly. d. This code compiles and...

  • Create the database and tables for the database. Show all SQL statements. Include primary and foreign...

    Create the database and tables for the database. Show all SQL statements. Include primary and foreign keys. Insert data into each table. Show select statements and display the output of each table. Note:Student’s name must be inserted into table as part of the data! Perform the SQL below: Query one table and use WHERE to filter the results. The SELECT clause should have a column list, not an asterisk (*). State the purpose of the query; show the query and...

  • Please help me on the SQL queries, thank you so much. Write a query to display the title and publisher as well as the p...

    Please help me on the SQL queries, thank you so much. Write a query to display the title and publisher as well as the publisher contact for each book using JOIN...USING clause. Write a query to show the first and last names of customers who have ordered cooking books. Use the WHERE clause to join the tables. Write a query to show the title, cost and ISBN of each book in the books table. If the book has been ordered,...

  • K3 K3 School of CS & IT, RMIT Introduction to Database Systems Tutorial Sheet 2: SQL...

    K3 K3 School of CS & IT, RMIT Introduction to Database Systems Tutorial Sheet 2: SQL The database below is for a department store, and describes stock, staff, clients, and sales. Each question in this tutorial concerns this "store" database. SALE ITEM ITEM STAFF NUMSOLD CLIENT SDATE TYPE DESCRIP PRICE K3 Simon 6 Clark 19980311 Knife set $17.95 K11 Simon Cilla 19980121 K5 Ladle $6.95 K11 Simon Cilla 19980123 K11 Scraper $0.95 L12 Sorcha 5 Charles 19971130 L12 Rack $22.95...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT