Friday, March 12, 2010

Some Basic SQL Queries

1) Query to select Maximum Salary from a Table

Select Max (ActualSalary) from employees


2) Query to select Minimum Salary from a Table

Select Min (ActualSalary) from employees


3) Query to select unique values from a table

Select Distinct EmpStatusCode from employees


4) Query to select 6th highest Salary

SELECT TOP 1 ActualSalary
FROM (SELECT DISTINCT TOP 6 ActualSalary FROM employees
ORDER BY ActualSalary DESC) a
ORDER BY ActualSalary


5) Query to select total count from table

SELECT count (* or field name) from employees


6) Query for ascending order display

SELECT * from employees Order by LastName


7) Query for Descending Order display

SELECT * from employees Order by LastName DESC



8) Query to insert Values into a table

INSERT INTO Persons (P_Id, Last Name, FirstName)
VALUES (5, 'Tjessem', 'Jacob')


9) Query to update values in a table

SET EmpID =1000 WHERE LastName=’Rakesh’


10) Query to delete a value from a table

Delete from employees where EmpID=1000



If you know some basic queries other than this, kindly drop it in the comment section.

No comments:

Post a Comment