Вы находитесь на странице: 1из 23

Experiment -1

AIM: To crate a table.


SYNTEX:
Create table table_name (attributes datatype(size);

Example:

CREATE TABLE WORKER(WID INTEGER(10),WNAME


VARCHAR(20),COMPANY VARCHAR(30),PHONENUMBER
INTEGER(50),CITY VARCHAR(10),SALARY
INTEGER(12),DATEOFJOINING VARCHAR(20));

BEFORE:

AFTER:

EXPERIMENT-2

AIM: Insertion of values to the table.


SYNTEX:
INSERT INTO table_name VALUES(attributes values);

Example:

INSERT INTO WORKER VALUES(1,'ANKIT','Adi


Technologies',8824679747,'DELHI',35000,'1 OCTOBER 2004');

OUTPUT:

Experiment-3

AIM:
Delete duplicate row from the table.

SYNTAX:

DELETE FROM table_name


WHERE some_column=some_value;

EXAMPLE:

DELETE FROM WORKER WHERE WID=2;

OUTPUT:
BEFORE:

AFTER:

EXPERIMENT-4
AIM:
Display the alternate row from table.

SYNTAX:

SELECT * FROM<table_name>WHERE MOD(primary key,2)<>0;

EXAMPLE:

select * from <table name> where mod(rollno,2)<>0;

OUTPUT:
BEFORE:

AFTER:

EXPERIMENT-5
AIM Update multiple rows in using single update statement.
SYNTAX:
UPDATE table_name
SET column1=value1,column2=value2,...
WHERE some_column=some_value;

Example:

UPDATE WORKER
SET WNAME='SHAILANK', City='BANARAUS'
WHERE WNAME=PIYUSH';
BEFORE:

AFTER:

EXPERIMENT-6
AIM:
Update multiple rows in using single update statement.

SYNTAX:

UPDATE table_name
SET column_name_1=CASE column_name_2
WHEN some_value THEN some_value
WHEN some_value THEN some_value
.
.
.
END
column_name_3= CASE column_name_2
WHEN some_value THEN some_value
WHEN some_value THEN some_value
.
.
.
END
WHERE column_name_2 IN(some_value(s));

EXAMPLE:

UPDATE WORKER
SET COMPANY = CASE WID
WHEN 1 THEN "Certpoint Systems"
WHEN 4 THEN "Google"
WHEN 10 THEN "Proginet"
END,
CITY= CASE WID
WHEN 1 THEN "New York"
WHEN 4 THEN "California"
WHEN 10 THEN "New York"
END
WHERE WID IN (1,4,10);
OUTPUT:

BEFORE:

AFTER:

EXPERIMENT-7
AIM:
Find the third highest paid and third lowest paid salary

SYNTAX:

SELECT SALARY AS 3rd highest/lowest salary


FROM(SELECT SALARY FROM table ORDER BY SALARY desc/asc
LIMIT 2,1)
ANY_VARIABLE ORDER BY SALARY asc/desc;

EXAMPLE:
FOR THIRD HIGHEST PAID SALARY:
SELECT SALARY AS 3rd HIGHEST SALARY
FROM (SELECT SALARY FROM WORKER ORDER BY SALARY DESC
LIMIT 2,1)
Q ORDER BY SALARY ASC;

FOR THIRD LOWEST PAID SALARY:

SELECT SALARY AS 3rd LOWEST HIGHEST SALARY


FROM (SELECT SALARY FROM WORKER ORDER BY SALARY ASC
LIMIT 2,1)
Q ORDER BY SALARY DESC;

OUTPUT: FOR THIRD HIGHEST PAID SALARY

FOR THIRD LOWEST PAID SALARY:

EXPERIMENT-8
AIM:
Display the 3rd, 4th, 9th rows from table.

SYNTAX:

SELECT * FROM table_name WHERE field1= value OR field1= value OR


field1 =value;

EXAMPLE:

SELECT * FROM WORKER WHERE WID =3 OR WID=4 OR WID=9;

OUTPUT:

EXPERIMENT-9
AIM:
Display the ename , which is start with j, k, l or m.

SYNTAX:

SELECT * FROM table_name WHERE ENAME LIKE 'j%' OR ENAME


LIKE 'K%' OR ENAME LIKE 'L%' OR ENAME LIKE 'M%';

EXAMPLE:

SELECT * FROM WORKER WHERE WNAME LIKE 'j%' OR WNAME


LIKE 'K%' OR WNAME LIKE 'L%' OR WNAME LIKE 'M%';

OUTPUT:

EXPERIMENT-10
AIM: Show selected wname salary by nested query..
SYNTAX: SELECT first_name,last_name, salary FROM emp_details
WHERE salary >(SELECT salary FROM emp_details WHERE
first_name='Alexander');

Example: SELECT WNAME,SALARY FROM WORKER WHERE


SALARY >(SELECT SALARY FROM WORKER WHERE
WNAME='LAXMI');

OUTPUT:

EXPERIMENT-11
AIM: display inner join operation query..
SYNTAX: SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name=table2.column_name;
or:
SELECT column_name(s)
FROM table1
JOIN table2
ON table1.column_name=table2.column_name;

Example:
SELECT CUSTOMER.CNAME,CONSUMER.ONO
FROM CUSTOMER
INNER JOIN CONSUMER
ON CUSTOMER.CID=CONSUMER.CID
ORDER BY CUSTOMER.CNAME;

OUTPUT:
Tables1

Tables2

AFTER

EXPERIMENT-12
AIM: DISPLAY THE LEFT OUTER JOIN OPERATION QUERY
SYNTAX:
SQL LEFT JOIN Syntax
SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name=table2.column_name;
Example:
SELECT Customer.CName, CONSUMER.ONO
FROM Customer
LEFT JOIN CONSUMER
ON Customer.CID=CONSUMER.CID
ORDER BY Customer.CName;

OUTPUT:
Tables1

Tables2

AFTER