0% found this document useful (0 votes)
34 views2 pages

Untitled

The document demonstrates various SQL commands like creating and updating tables, inserting data, selecting data using where clauses, aggregate functions, joins, unions and intersections. It creates two tables called to_update, courses and hod, inserts sample data, demonstrates updating a record in to_update table, uses aggregate functions like max, min, avg on hod table, performs joins, unions and intersections between courses and hod tables.

Uploaded by

Vaibhav Saluja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views2 pages

Untitled

The document demonstrates various SQL commands like creating and updating tables, inserting data, selecting data using where clauses, aggregate functions, joins, unions and intersections. It creates two tables called to_update, courses and hod, inserts sample data, demonstrates updating a record in to_update table, uses aggregate functions like max, min, avg on hod table, performs joins, unions and intersections between courses and hod tables.

Uploaded by

Vaibhav Saluja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 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