Untitled

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

-----------------------UPDATE a table------------------

create table to_update(cid number(10), name varchar(20));


insert into to_update(cid, name) values(100, 'rohan');
insert into to_update(cid, name) values(102, 'sara');

select * from to_update;

UPDATE to_update SET name= 'shnaya' WHERE cid=102;

---------------CREATE two tables to perform operations----------------

create table courses(cid number(10), course varchar(20));

insert into courses (cid, course) values(100, 'database');


insert into courses (cid, course) values(101, 'mechanics');
insert into courses (cid, course) values(102, 'electronics');

select * from courses;

create table hod(cid number(10), name varchar(20));

insert into hod (cid, name) values(100, 'rohan');


insert into hod (cid, name) values(102, 'sara');
insert into hod (cid, name) values(104, 'jiya');

select * from hod;

----------------AGGRIGATE FUNCTIONS---------------------

SELECT MAX(cid) FROM hod;


SELECT AVG(cid) FROM hod;
SELECT MIN(cid) FROM hod;
SELECT COUNT(*) FROM hod;
SELECT DISTINCT cid FROM hod;

---------------------WHERE CLAUSE-------------

SELECT name, cid FROM hod WHERE name='jiya';

SELECT name, cid FROM hod WHERE cid=100;

--------------------------LIKE---------------

SELECT * FROM hod WHERE name LIKE '%n';

-------------------------ORDER BY-----------------
SELECT cid, name FROM to_update WHERE cid>10 ORDER BY name DESC;

SELECT cid, name FROM to_update WHERE cid>10 ORDER BY name ASC;

--------------------OPERATIONS-------------------------

SELECT * from courses


UNION
SELECT * FROM hod;

SELECT cid from courses


INTERSECT
SELECT cid FROM hod;

--------------------JOINS----------------------------------
SELECT courses.cid, courses.course, hod.name, hod.cid
FROM courses
INNER JOIN hod ON courses.cid = hod.cid;

SELECT courses.cid, courses.course, hod.name, hod.cid


FROM courses
LEFT JOIN hod
ON courses.cid = hod.cid;

SELECT courses.cid, courses.course, hod.name, hod.cid


FROM courses
RIGHT JOIN hod
ON courses.cid = hod.cid;

SELECT courses.cid, courses.course, hod.name, hod.cid


FROM courses
FULL OUTER JOIN hod
ON courses.cid = hod.cid;

You might also like