MS SQL Training (Clause) Part-3

Written by creation2018, September 3, 2018


MS SQL Clauses
Where
In
Between
Like
Order By
Group By
Having

create table Customers(
CustomerId int Primary key,
Name varchar(100),
Email varchar(100),
Mobile varchar(20),
City varchar(20)
);

select * from Customers;

insert into Customers values(1,’Aditya’,’[email protected]’,’9876453789′,’Pune’);
insert into Customers values(2,’Sumit’,’[email protected]’,’8676453778′,’Mumbai’);
insert into Customers values(3,’Sanket’,’[email protected]’,’9879032451′,’Nagpur’);
insert into Customers values(4,’Manish’,’[email protected]’,’7689675847′,’Delhi’);
insert into Customers values(5,’Tushar’,’[email protected]’,’9834577623′,’Pune’);

select * from Customers where CustomerId=2;
select * from Customers where CustomerId in (1,3,5);

select * from Customers where CustomerId between 2 and 4;

select * from Customers where Name Like(‘S%’);
select * from Customers where Name Like(‘%S’);
select * from Customers where Name Like(‘%S%’);

select * from Customers Order by Name ASC;
select * from Customers Order by Name DESC;

select City,Count(CustomerId) as TotalCustomer from Customers Group by City;
select City,Count(CustomerId) as TatalCustomer from Customers Group by City having City=’Pune’;