Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

what is the difference between group and having
give an example with query and sample output

Answer Posted / soorai ganesh

create table lovepair (boyfrndname varchar(10),girlfrndname
varchar(10))

insert into lovepair values ('BF1','GF1')
insert into lovepair values ('BF1','GF2')
insert into lovepair values ('BF1','GF3')
insert into lovepair values ('BF2','GF1')
insert into lovepair values ('BF2','GF2')
insert into lovepair values ('BF3','GF3')
insert into lovepair values ('BF3','GF3')
insert into lovepair values ('BF3','GF3')

-- Here BF1 have 3 Girl Friends. like the BF2 and BF3 have
2 and 3 Girl Friends Simultaneously.

-- Here is the query for, how many girls friends each boys
have ???? USING group by

SELECT boyfrndname, COUNT (*)
FROM lovepair
GROUP BY boyfrndname

// Here another qry for who have more than 2 girl
friends ?? USING GroupBy and Having .

// Having is used for applying some condition in Aggregate
function

SELECT boyfrndname,COUNT(*)
FROM lovepair
Group BY boyfrndname
having count(*)>2


--- Now u clear...........

Is This Answer Correct ?    4 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do use Having,Group by,Group function in SQL?

1692


What is the meaning of lock escalation and why/how to stop this? : sql server database administration

986


What is an etl file?

900


You have a table ‘test’ which is a copy of northwind employee table you have written a trigger to update the field ‘hiredate’ with the current date

991


What are the steps to take to improve performance of a poor performing query? : sql server database administration

978


How do I trace a query in sql server?

900


What different steps will a sql server developer take to secure sql server?

928


What is difference between getdate and sysdatetime in sql server 2008?

999


What to perform pattern match with the like operator?

838


What is meant by indexing?

939


Differentiate between sql temp table vs table variable?

830


What is merge join?

1125


Can we join two tables without primary key?

979


How to create sub reports?

226


What is ssrs?

117