# SQL Notes: Exercise 3 - SELECT Using Inner Joins - Answers

Name: ANSWERS

Write a SELECT statement which produces the results. Put each clause (FROM, WHERE, ...) on a separate line. Unless otherwise specified, use the example database from the book SQL: The Complete Reference.

1. List the (busy) salesreps who have taken orders for other (lazy) salesreps. These are the orders where the rep that took the order is not the same as the customer's rep. Give their names and the amount of each order. Note that this uses a table which doesn't appear in the SELECT output, but is necessary to cause the correct records (rows) to appear.

       SELECT Busy.name, amount, Lazy.name
          FROM Salesreps Busy, Orders, Salesreps Lazy, Customers
          WHERE Orders.rep  = Busy.empl_num        /* order taken by  "busy" rep */
            AND Orders.cust = Customers.cust_num   /* orders for this customer   */
            AND Customers.cust_rep = Lazy.empl_num /* identify cust's "lazy" rep */
            AND Busy.empl_num <> Busy.empl_num;    /* Two different reps         */

2. Would there be any change in the WHERE clause if we didn't need to see the amount of the order? Ie, SELECT Busy.name, Lazy.name.
3. Identify two alternate not-equal comparisons that we could have used.