SQL SERVER -- Query Basics-- Part-15
Query Basics:-
Lets see how to pull data from Tables using basic SQL Query
SELECT :-
Used to Retrieve data from the Table OR View
How to Retrieve all the columns from the Table:-
SELECT * FROM EMP
How to Retrieve Specific(Selected) columns from the Table:-
WHERE :-
Where Clause is Used to filter the data based any column.
ORDER BY :-
Order by Clause is Used to Sort the data either in ascending OR Descending order based on any column.
HAVING :-
Having Clause is Used filter Aggregated Data.
SELECT LOC,COUNT(EMPID) AS EmpCount
Used to Retrieve data from the Table OR View
How to Retrieve all the columns from the Table:-
SELECT * FROM EMP
How to Retrieve Specific(Selected) columns from the Table:-
SELECT EMPNAME
,SAL
,LOC
FROM EMP
Where Clause is Used to filter the data based any column.
SELECT *
FROM EMP
WHERE LOC='Bangalore'
GROUP BY :-
Group By Clause is Used to Group the data and perform Aggregate Operations like Totals and sub totals.
SELECT LOC,COUNT(EMPID) AS EmpCount
FROM EMP
GROUP BY LOC
Order by Clause is Used to Sort the data either in ascending OR Descending order based on any column.
SELECT *
FROM EMP
ORDER BY EMPNAME DESC
SELECT *
FROM EMP
ORDER BY EMPNAME ASC
HAVING :-
Having Clause is Used filter Aggregated Data.
SELECT LOC,COUNT(EMPID) AS EmpCount
FROM EMP
GROUP BY LOC
HAVING COUNT(EMPID)=1