(employee_number, last_name, first_name, salary, dept_id) VALUES (1004, 'Horvath', 'Jack', 42000, 501); Solution for Practice Exercise #1: The following SQL SELECT statement would select these records from the employees table: SELECT * FROM employees WHERE salary <= 52500;
Practice Exercise #2:
Based on the suppliers table below, select the unique city values that reside in the state of California and order the results in descending order by city:
CREATE TABLE suppliers
( supplier_id int NOT NULL, supplier_name char(50) NOT NULL, city char(50), state char(25), CONSTRAINT suppliers_pk PRIMARY KEY (supplier_id) );
INSERT INTO suppliers
(supplier_id, supplier_name, city, state) VALUES (100, 'Microsoft', 'Redmond', 'Washington');
INSERT INTO suppliers
(supplier_id, supplier_name, city, state) VALUES (200, 'Google', 'Mountain View', 'California'); INSERT INTO suppliers (supplier_id, supplier_name, city, state) VALUES (300, 'Oracle', 'Redwood City', 'California');
INSERT INTO suppliers
(supplier_id, supplier_name, city, state) VALUES (400, 'Kimberly-Clark', 'Irving', 'Texas');
INSERT INTO suppliers
(supplier_id, supplier_name, city, state) VALUES (500, 'Tyson Foods', 'Springdale', 'Arkansas');
INSERT INTO suppliers
(supplier_id, supplier_name, city, state) VALUES (600, 'SC Johnson', 'Racine', 'Wisconsin');
(supplier_id, supplier_name, city, state) VALUES (800, 'Flowers Foods', 'Thomasville', 'Georgia');
INSERT INTO suppliers
(supplier_id, supplier_name, city, state) VALUES (900, 'Electronic Arts', 'Redwood City', 'California'); Solution for Practice Exercise #2: The following SELECT statement would select these records from the suppliers table: SELECT DISTINCT city FROM suppliers WHERE state = 'California' ORDER BY city DESC;
Practice Exercise #3:
Based on the customers table and the orders table below, select the customer_id and last_name from the customers table and select the order_date from the orders table where there is a matching customer_id value in both the customers and orders tables. Order the results by customer_id in descending order.
CREATE TABLE customers
( customer_id int NOT NULL, last_name char(50) NOT NULL, first_name char(50) NOT NULL, favorite_website char(50), CONSTRAINT customers_pk PRIMARY KEY (customer_id) );
CREATE TABLE orders
( order_id int NOT NULL, customer_id int, order_date date, CONSTRAINT orders_pk PRIMARY KEY (order_id) );
(order_id, customer_id, order_date) VALUES (5,null,'2016/05/01'); Solution for Practice Exercise #3: The following SQL SELECT statement would select these records from the customers and orders table (using an INNER JOIN): SELECT c.customer_id, c.last_name, o.order_date FROM customers c JOIN orders o ON c.customer_id = o.customer_id ORDER BY c.customer_id DESC;
Practice Exercise #4:
Based on the customers and orders table from Practice Exercise #3, select the customer_id and last_name from the customers table where there is a record in the orders table for that customer_id. Order the results in ascending order by last_name and then descending order by customer_id.
CREATE TABLE customers
( customer_id int NOT NULL, last_name char(50) NOT NULL, first_name char(50) NOT NULL, favorite_website char(50), CONSTRAINT customers_pk PRIMARY KEY (customer_id) );
CREATE TABLE orders
( order_id int NOT NULL, customer_id int, order_date date, CONSTRAINT orders_pk PRIMARY KEY (order_id) );