You are on page 1of 4

CREATE TABLE Employees

(
EMP_ID INTEGER,
EMP_NAME VARCHAR(30)
);

CREATE TABLE Location


(
EMP_ID INTEGER,
EMP_LOC varchar(50)
);

INSERT INTO EMPLOYEES(101,'Ranjith');


INSERT INTO EMPLOYEES(102,'Sham');
INSERT INTO EMPLOYEES(103,'Mohit');
INSERT INTO EMPLOYEES(104,'Irfan');
INSERT INTO EMPLOYEES(105,'Raj');
INSERT INTO EMPLOYEES(106,'Denis');

SEL * FROM EMPLOYEES;

INSERT INTO LOCATION(101,'USA');


INSERT INTO LOCATION(102,'UK');
INSERT INTO LOCATION(103,'MUMBAI');
INSERT INTO LOCATION(104,'DELHI');
INSERT INTO LOCATION(105,'DUBAI');
INSERT INTO LOCATION(106,'AUSTRALIA');

sel * from LOCATION;

sel * from EMPLOYEES where EMP_ID in(sel EMP_ID from LOCATION where
EMP_ID='101');

sel * from LOCATION where EMP_ID NOT IN(sel EMP_ID from EMPLOYEES where
EMP_ID='101');

CREATE TABLE Salary


(
EMP_ID INTEGER,
EMP_SAL INTEGER
);

INSERT INTO SALARY(101,'10000');


INSERT INTO SALARY(102,'20000');
INSERT INTO SALARY(103,'30000');
INSERT INTO SALARY(104,'40000');
INSERT INTO SALARY(105,'50000');
INSERT INTO SALARY(106,'60000');

sel * from salary;

select * from Employees where emp_id in(select emp_id from location where
EMP_ID in(select emp_id from Salary where EMP_SAL='50000'));

SEL * FROM Employees E1 WHERE E1.EMP_ID in (SEL E2.EMP_ID FROM SALARY E2


WHERE E1.EMP_ID = E2.EMP_ID);

show table Employees;

help table Employees;

sel * from Employees sample 4;

sel top 3 emp_id,emp_name from Employees order by 2 desc;

sel * from SAlary;

sel * from location;

sel MAX(EMP_SAL) from salary;

sel MIN(EMP_SAL) from salary;

sel AVG(EMP_SAL) from salary;

sel COUNT(*) from salary;

sel * from salary order by 2 desc;

sel EMP_ID,EMP_LOC from LOCATION where EMP_LOC in('USA','DUBAI') group by


emp_id,emp_loc;

SEL E.emp_id,emp_name,l.emp_id,l.emp_loc FROM EMPloyees E LEFT outer JOIN

location l ON E.emp_id=l.emp_id where l.EMP_id is not null;

SEL E.emp_id,emp_name,l.emp_id,l.emp_loc FROM location l right outer join


employees e ON l.emp_id=e.emp_id where l.EMP_id is not null;

SEL E.emp_id,emp_name,l.emp_id,l.emp_loc FROM EMPloyees E full outer JOIN


location l ON E.emp_id=l.emp_id where l.EMP_id is not null;

INSERT INTO EMPLOYEES(107,'Harjith');

INSERT INTO LOCATION(109,'NZ');

sel * from location;

sel current_date;

sel current_time;

select top 10 emp_id,emp_name from employees;

You might also like