Q13. Answer The Following Questions On Joins For ORDERS' and

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

Q13.

Answer the following questions on joins for ORDERS and


CUSTOMERS table :
mysql> creat table customers
-> (cust_code varchar(5) primary key,
-> name varchar(30),
-> address varchar(30),
-> phone varchar(30),
-> category char(1));

mysql> create table orders


-> (order_no int primary key,
-> cust_code varchar(5),
-> shoes_code int,
-> qtty int,
-> order_date date,
-> target_date date,
-> foreign key (cust_code) references customers(cust_code));
1) Identify the primary key in customers and orders table.
Primary key cust_code in customer table.
Orderno in orders table.

2) Identify the foreign key in customers and orders table.


Foreign key cust_code in orders table.

3)Display the cust_code, name, shoe code and total.


mysql> select name, o.cust_code, shoes_code
-> from orders o, customers c
-> where c.cust_code=o.cust_code;
4) Display the customer code and total qty ordered by each
customer.
mysql> select o.cust_code,name, sum(qtty) "Total Quantity"
-> from orders o, customers c
-> where c.cust_code=o.cust_code
-> group by o.cust_code;

5) Display only those customers where purchase qtty is greater than


50.
mysql> select name, qtty
-> from customers c, orders o
-> where c.cust_code=o.cust_code
-> and qtty>500;

6) Add two more rows in customers table.


mysql> insert into customers
-> values('C006','Nike','Kerela',8900074735,'B');
mysql> insert into customers
-> values('C007','Puma','Kashmir',9112374735,'C');
7) Display all customer names, their code and order qtty. Display
the name of all customer names whether they have placed an order
or not.
mysql> select name, qtty, c.cust_code
-> from customers c, orders o
-> where c.cust_code=o.cust_code;

8) Write the cartesian join query for customers and orders table.
mysql> select* from orders,customers;

You might also like