Question

This problem is from Chapter 5 of A Guide to SQL ninth addition. 9. For each...

This problem is from Chapter 5 of A Guide to SQL ninth addition.

9. For each item, list the item number, description, units on hand, order number, and number of units ordered. All items should be included in the results. For those items that are currently not on order, the order number and number of units ordered should be left blank. Order the results by item number.

All answers I have come up with use the full outer join, however, our professor is asking us to use SQLITE which does not support this command. Is there another solution?

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

Since you have come with all the answers with Full Outer Join.

But the problem is SQLITE doesn't support this command.

Solution: The way to solve your problem is to implement FULL OUTER JOIN using UNION ALL and LEFT JOIN

commands available in SQLITE.

Lets see an Example on how to implement this::

// We have created a table named "dogs"

CREATE TABLE dogs (

    type       TEXT,

    color TEXT

);

// Now we are inserting the values into the table "dogs"

INSERT INTO dogs(type, color) VALUES('Hunting','Black'), ('Guard','Brown');

// similarly create and insert data into the cats table

CREATE TABLE cats (

    type       TEXT,

    color TEXT

);

INSERT INTO cats(type,color) VALUES('Indoor','White'), ('Outdoor','Black');

// Using of FULL OUTER JOIN

// The following statement uses the FULL OUTER JOIN clause to query data from the dogs and cats tables.

SELECT * FROM dogs

FULL OUTER JOIN cats

    ON dogs.color = cats.color;

// Result of above executed Query

Type Color Type Color
Hunting Black Outdoor Black
Guard Brown NULL NULL
NULL NULL Indoor White

// Now we will try to get same result using UNION ALL and LEFT JOIN commands

SELECT d.type, d.color, c.type, c.color

FROM dogs d

LEFT JOIN cats c USING(color)

UNION ALL

SELECT d.type, d.color, c.type, c.color

FROM cats c

LEFT JOIN dogs d USING(color)

WHERE d.color IS NULL;

// Now we will see how this query works.

  • Because SQLilte does not support the RIGHT JOIN clause, we use the LEFT JOIN clause in the second SELECT statement instead and switch the positions of the cats and dogs tables.
  • The UNION ALL clause retains the duplicate rows from the result sets of both queries.
  • The WHERE clause in the second SELECT statement removes rows that already included in the result set of the first SELECT statement.

Hence in this way you can change all your queries to get your required result in SQLITE.

Add a comment
Know the answer?
Add Answer to:
This problem is from Chapter 5 of A Guide to SQL ninth addition. 9. For each...
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
  • PART II: Answer 4 of the 5 problems from this part (13 pts each; 52 pts total) important Fil out the box accompanying each problem to indicate if it should be graded If you leave the boxes blank,...

    PART II: Answer 4 of the 5 problems from this part (13 pts each; 52 pts total) important Fil out the box accompanying each problem to indicate if it should be graded If you leave the boxes blank, we will not count your best 4 problems. l-1. Relational Model and SQL (13 pts total) Recall the relations in our movie database DONT GRADE GRADE Movie(id, name, year, rating, runtime, genre, earnings rank) Person(id, name, dob, pob) Directori director id, movie...

  • There are 7 problems that require using joins. Each problem has 10 points. 1. Write an...

    There are 7 problems that require using joins. Each problem has 10 points. 1. Write an SQL command that will find any customers who have not placed orders and sort them out by CustomerID in ascending order. 2. List the employees and supervisors names for each supervisor who supervises more than two employees. 3. List the name of each employee, his or her birth date, the name of his or her manager, and the manager’s birth date for those employees...

  • We are using, Oracle Database 11g Express Edition. use SQL and the TAL Distrutors database (see...

    We are using, Oracle Database 11g Express Edition. use SQL and the TAL Distrutors database (see figure 1-2 in chapter 1) to complete the following exercises. if directed to do so by your instructor, use the information provided with the chapter 3 exercises to print your output or save it to a document. 1. list the item number, description, and price for all items. 2. list all rows and columns for the complete ORDERS table. 3. list the names of...

  • SQL Homework 1. For each reservation, list the reservation ID, trip ID, customer number, and customer...

    SQL Homework 1. For each reservation, list the reservation ID, trip ID, customer number, and customer last name. Order the results by customer last name. 2. For each reservation for customer Ryan Goff, list the reservation ID, trip ID, and number of persons. 3. List the trip name of each trip that has Miles Abrams as a guide. 4. List the trip name of each trip that has the type Biking and that has Rita Boyers as a guide. 5....

  • ONLY ODD NUMBERS. YOU MUST USE ORACLE OR MY SQL. THANKS Chapter 3 TAL Distributors Use...

    ONLY ODD NUMBERS. YOU MUST USE ORACLE OR MY SQL. THANKS Chapter 3 TAL Distributors Use SQL to complete the following exercises 1. Create a table named SALES_ REP. The table has the same structure as the REP table shown in Figure 3-11 except the LAST_NAME column should use the VARCHAR data type and the COMMISSION and RATE columns should use the NUMBER data type. Execute the command to describe the layout and characteristics of the SALES_REP table. Add the...

  • A guide to SQL 9th edition Colonial Adventure Tours chapter 3 page 90-92 Odd numbered exercises...

    A guide to SQL 9th edition Colonial Adventure Tours chapter 3 page 90-92 Odd numbered exercises only figure 3-39(Guide, trip, customer, reservation and Trip_Guides) figure 1-5 chapter 1: 7. Review me on TUI UTILIVUDIJ types used to create the ITEM table in Figure 3-34. Suggest alternate data types for the DESCRIPTION, ON HAND. and STOREHOUSE fields and explain your recommendation Colonial Adventure Tours Use SQL to complete the following exercises 1. Create a table named ADVENTURE TRIP. The table has...

  • 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...

  • 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...

  • Write the following SQL statements in Microsoft Access by using the Books database from Week 2...

    Write the following SQL statements in Microsoft Access by using the Books database from Week 2 Assignment 2. Once complete, copy and paste the SQL statements in a Microsoft Word document: Write SQL statements: To update the publisher name from READ WITH US to READ FOR US To verify the updated name field for the publisher with ID 6 To make the following updates to the Publisher table (be careful with WHERE): Make Contact="John Travolta" for publisher with ID number...

  • Create the following SQL Server queries that access the Northwind database Same as problem 3 but,...

    Create the following SQL Server queries that access the Northwind database Same as problem 3 but, limit the list to all customers who placed 3 or more orders. The product id, product name, last date that the product was ordered for all items in the Grains/Cereals category. (Hint: Use MAX) The product ID, product name, and number of distinct customers who ordered that product in 1996 Thank you. Categories Customers Employees Order Details Orders Products Shippers 9 CategoryID CategoryName Description...

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