Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create SQL queries to answer the following questions for the tables below: REP T

ID: 662607 • Letter: C

Question

Create SQL queries to answer the following questions for the tables below:

REP Table

REP_ID

REP_LNAME

REP_FNAME

REP_STREET

REP_CITY

REP_STATE

REP_ZIP

REP_COMM

REP_RATE

223

Roma

Theresa

735 First

Leonard

GA

25742

$21,756.50

0.06

    237

Miller

Fred

643 High

Sheldon

GA

25753

$38,612.00

0.08

268

Rodriguez

Miguel

2737 Tyler

Springfield

GA

25758

$19,774.00

0.06

CUSTOMER Table

CUST_ID

CUST_NAME

CUST_STREET

CUST_CITY

CUST_STATE

CUST_ZIP

CUST_BALANCE

CUST_LIMIT

REP_ID

1159

Charles Appliance and Sport

3948 Brown

Leonard

GA

25742

$5,560.00

$7,500.00

223

     1193

Streaming Direct

4938 Maple

Grove

GA

25721

$210.40

$10,000.00

237

1367

Hollister

REP_ID

REP_LNAME

REP_FNAME

REP_STREET

REP_CITY

REP_STATE

REP_ZIP

REP_COMM

REP_RATE

223

Roma

Theresa

735 First

Leonard

GA

25742

$21,756.50

0.06

    237

Miller

Fred

643 High

Sheldon

GA

25753

$38,612.00

0.08

268

Rodriguez

Miguel

2737 Tyler

Springfield

GA

25758

$19,774.00

0.06

Explanation / Answer

1)

Select Cust_id ,Cust_name fromCustomer where Product.Product_Desc="Blendar" and Line.Product_id= Product.PROD_ID where exists (select Cust_id from Invoice whre Line.Invoice_num=Invoice.Invoice_Num)

2)

Select Invoice_num,Ivoice_date from Invoice where Customer.Cust_id=Invoice.Cust_id and Cutomer.Name="Charles Appliance and Sport."

3)

Select Invoice_Num, Invoice_Date from Invoice Product_id from Line where invoice.invoice_num=Line.Invoice_Num and Product.Product_desc="Electric Range."

4)

The SQL UNION operator combines the result of two or more SELECT statements.

The SQL UNION Operator

The UNION operator is used to combine the result-set of two or more SELECT statements.

Notice that each SELECT statement within the UNION must have the same number of columns. The columns must also have similar data types. Also, the columns in each SELECT statement must be in the same order.

SQL UNION Syntax

SELECT column_name(s) FROM table1
UNION
SELECT column_name(s) FROM table2;

Note: The UNION operator selects only distinct values by default. To allow duplicate values, use the ALL keyword with UNION.

SQL UNION ALL Syntax

SELECT column_name(s) FROM table1
UNION ALL
SELECT column_name(s) FROM table2;

PS: The column names in the result-set of a UNION are usually equal to the column names in the first SELECT statement in the UNION.

Select Invoice_Num,Invoice_date from Invoice where Customer.Cut_id= Invoice.Cust_id and Customer.Cust_name="Appliance and Sport" Or "Electric Range".

5)

Select Invoice_Num,Invoice_date from Invoice where Customer.Cut_id= Invoice.Cust_id and Customer.Cust_name="Appliance and Sport" Or "Electric Range".