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

SQL Queries

This document contains SQL statements to create databases and tables, insert, update, delete and select data from tables, find maximum, minimum, count and duplicate records, and copy records between tables. It demonstrates various SQL commands for managing databases and querying data.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views2 pages

SQL Queries

This document contains SQL statements to create databases and tables, insert, update, delete and select data from tables, find maximum, minimum, count and duplicate records, and copy records between tables. It demonstrates various SQL commands for managing databases and querying data.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

create database DbSample Use DbSample Create table TblEmp_Mast(EID int Primary Key, Ename Varchar(250), Add1 varchar(250),

Add2 Varchar(250), City varchar(100)) Select * from TblEmp_Mast where City<>'chennai' Create table TblEmp_Det(EID int, Doj Datetime, Salary numeric(12,2)) insert into TblEmp_Det values(102, '2008/03/21',15000) Delete from TblEmp_Det delete from tblemp_mast select a.Ename,b.doj from TblEmp_Mast a left join TblEmp_Det b on a.EID=b.EID Create table TblEmp_Mast1(EID int Primary Key not null, mobile numeric(12)) Insert into TblEmp_Mast values(104,'Ramesh','123,Palani Gounder St','Rathinapuri','Coimbatore');insert into TblEmp_Det values(104,'2011/03/21',10000); delete from TblEmp_Det where EID=104 select ename,city from TblEmp_Mast where City not in ('Chennai') delete from tblemp_mast1

To insert the multiple records in table by using single query:


Insert into TblEmp_Mast values(101,'Suresh','123,Palani Gounder St','Rathinapuri','Coimbatore'),(102,'Babu','56, Anna Nagar','Mount Road','Chennai'),(103,'Shankar','142, Kamaraj St',' Gandhi Maanagar ','Madurai')

To Find the 2nd maximum salary in Table:


select MAX(salary) from TblEmp_Det where Salary<>(select MAX(salary) from TblEmp_Det)

To Find the total no of Records in Table with condition:


select COUNT(*) from TblEmp_Mast where City='chennai'

To Find the 2nd minimum salary in Table:


select MIN(salary) from TblEmp_Det where Salary not in (select MIN(salary) from TblEmp_Det)

To Find the Duplicate Records in Table:


SELECT ENAME FROM TblEmp_Mast GROUP BY Ename HAVING COUNT(*)>1

To copy the records from existing table to new table:


SELECT * INTO TBLEMP_MAST1 FROM TblEmp_Mast SELECT EID,Ename INTO TblEmp_Mast1 FROM TblEmp_Mast WHERE City='Coimbatore' SELECT TblEmp_Mast.Ename,TblEmp_Det.Salary INTO TblEmp_Mast3 FROM TblEmp_Mast INNER JOIN TblEmp_Det ON TblEmp_Mast.EID=TblEmp_Det.EID

You might also like