TEXT 34
Database System Lab 7 Guest on 18th May 2021 12:08:51 PM
  1. select * from jobs, departments
  2.  
  3. -- having clause
  4. -- having clause  is used in combination with the group by clause
  5.  
  6. select department_id, sum(salary) total_salary  from employees group by department_id;
  7. select department_id, sum(salary) total_salary  from employees group by department_id having sum(salary) > 58000;
  8.  
  9.  
  10. create table supplier(
  11.     supplier_id number(10) not null primary key,
  12.     supplier_name varchar(20) not null,
  13.     supplier_contact_name varchar(50)
  14. )
  15.  
  16. insert into supplier (supplier_id, supplier_name, supplier_contact_name) values (10000, 'IBM', 'abc');
  17. insert into supplier (supplier_id, supplier_name, supplier_contact_name) values (10001, 'HP', 'def');
  18. insert into supplier (supplier_id, supplier_name, supplier_contact_name) values (10002, 'Microsoft', 'ghi');
  19. insert into supplier (supplier_id, supplier_name, supplier_contact_name) values (10003, 'NVIDIA', 'jkl');
  20.  
  21. alter table supplier drop primary key;
  22.  
  23. alter table supplier add PRIMARY KEY (supplier_id);
  24.  
  25. create table customer(
  26. customer_id number(10) not null,
  27. customer_name varchar(30) not null,
  28. customer_city varchar(20) null,
  29. CHECK (customer_id > 0)
  30. );
  31.  
  32. To make sure that customer_id is greater than 0
  33.  
  34. insert into customer(customer_id, customer_name, customer_city) values (-2, 'Test', 'Testing');
  35.  
  36. -- alter table table_name check (col_name > condition);
  37.  
  38. select * from t1 natural join t2;
  39. to get all common
  40.  
  41. Inner Join
  42. -- inner join
  43. -- syntax
  44. --select columns from table1 inner join table2 ON table1.column = table2.column
  45.  
  46. create table orders(
  47. order_id number(10) not null,
  48. supplier_id number(10) not null,
  49. order_data varchar(20) null);
  50.  
  51. insert into orders(order_id, supplier_id, order_data) values (500125, 10000, '2003');
  52. insert into orders(order_id, supplier_id, order_data) values (500126, 10001, '2005');
  53. insert into orders(order_id, supplier_id, order_data) values (500127, 10003, '2006');
  54.  
  55.  
  56. -- applying inner join
  57. select supplier.supplier_id, supplier.supplier_name, orders.order_data from supplier inner join orders on supplier.supplier_id = orders.supplier_id;

Coding Base is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.