Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

AIR UNIVERSITY ISB

DATABASE SYSTEMS LAB


LAB ACTIVITIES
MUHAMMAD SAMI
221086
BSIT IV B

- Creating customer and orders tables

- Inserting data into the tables


AIR UNIVERSITY ISB

- Displaying customer data

- Displaying orders data

- Performing inner joins


SELECT od.orders_id, od.orders_detail, c.customer_id, c.first_name,
c.address FROM orders od
INNER JOIN customer c ON od.customer_id = c.customer_id;

SELECT customer.customer_id, customer.first_name,


customer.address,orders.customer_id,
orders.orders_detail,orders.total_amount FROM orders
INNER JOIN customer ON orders.customer_id = customer.customer_id
WHERE orders.total_amount > 300;
AIR UNIVERSITY ISB

- Performing Left Joins


SELECT customer.customer_id,
customer.first_name,customer.phone_number, orders.orders_id,
orders.orders_detail FROM customer
LEFT OUTER JOIN orders ON customer.customer_id = orders.customer_id;

SELECT c.customer_id, c.first_name, o.orders_detail, o.total_amount


FROM customer c
LEFT OUTER JOIN orders o ON c.customer_id = o.customer_id
WHERE o.orders_id >= 200;

- Performing right joins


SELECT orders.orders_id,orders.orders_detail, orders.total_amount,
customer.first_name, customer.phone_number FROM orders
RIGHT OUTER JOIN customer ON orders.customer_id =
customer.customer_id;

SELECT orders.customer_id, orders.total_amount, customer.phone_number


FROM orders
RIGHT OUTER JOIN customer ON orders.customer_id =
customer.customer_id
WHERE orders.total_amount >=300;
AIR UNIVERSITY ISB

- Performing count and sorting queries


SELECT COUNT(*) AS total_customers FROM customer;

SELECT * FROM customer ORDER BY last_name ASC;

SELECT * FROM orders ORDER BY total_amount DESC;


AIR UNIVERSITY ISB

You might also like