ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Do you have a collection of Interview Questions and interested to share with us!!
Please send that collection to along with your userid / name. ThanQ
Google
 
Categories  >>  Software  >>  Databases  >>  SQL Server
 
 


 

 
 Oracle interview questions  Oracle Interview Questions
 SQL Server interview questions  SQL Server Interview Questions
 MS Access interview questions  MS Access Interview Questions
 MySQL interview questions  MySQL Interview Questions
 Postgre interview questions  Postgre Interview Questions
 Sybase interview questions  Sybase Interview Questions
 DB Architecture interview questions  DB Architecture Interview Questions
 DB Administration interview questions  DB Administration Interview Questions
 DB Development interview questions  DB Development Interview Questions
 SQL PLSQL interview questions  SQL PLSQL Interview Questions
 Databases AllOther interview questions  Databases AllOther Interview Questions
Question
what is the difference between group and having 
give an example with query and sample output
 Question Submitted By :: Klbaiju
I also faced this Question!!     Rank Answer Posted By  
 
  Re: what is the difference between group and having give an example with query and sample output
Answer
# 1
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 ?    1 Yes 2 No
Soorai Ganesh
 
  Re: what is the difference between group and having give an example with query and sample output
Answer
# 2
Group by is used To Group Result According To Group Name
Having Is Always Is Used With Group by Clause.
Having Contain Aggregate Function or Simple Sub Query .
as Show In Above Example
 
Is This Answer Correct ?    1 Yes 0 No
Dinesh Sharma
 
 
 

 
 
 
Other SQL Server Interview Questions
 
  Question Asked @ Answers
 
What value could be assigned to Varchar Type?  3
How do you simulate a deadlock for testing purposes  1
internal language used in sql server 2000?  1
Can we use Truncate command on a table which is referenced by FOREIGN KEY?  2
can you any body tell me the how to decrease the logfile  4
What is the difference between HAVING clause and the WHERE clause?  4
What are mdf,ndf,ldf files and how to see the data in those files? Accenture5
What is a Join in SQL Server?  2
What is the difference between a local and a global variable?  3
How to get the count of distinct records. Please give me the query? Value-Labs5
What are the main control-of-flow T-SQL constructs?  1
How do I list the available tables in a database I'm querying?  3
wht's the differece between sqlserver05 and sqlserver2000  3
What are the types of indexes available with SQL Server?  2
WHAT IS DIFFRENCE BETWEEN TRUNCATE AND DELETE STATEMENT CTS10
What are the advantages of using sql server over ms access or why should one use sql instead of ms access Impetus1
what is hash table Teledata2
what purpose does OPENXML clause have in sql server stored procedure?  1
1. What are the grouping function in SQL ? 2. If base table of a view deleted means, what will happen while we querying on view ? will give any error ? 3. Difference between DROP, DELETE, TRUNCATE table ? 4. What is constraints and types ? 5. What is max size of nchar & nvarchar ? 6. Define ROLLBACK, COMMIT, SAVE POINT 7. How non-clustered better ? or rank the Clustered, Non-Clustered and Table scan in performance wise 8. Select 10 rows from a table ? 9. Define DML, DDL, DCL, DTL commands ? 10. What is mean by NULL value ? NULL means "" or 0 or undefined ? 11. Default constraints ? 12. Can we have more then primary Key in table ? 13. Type of integrity ? Entity, Referential, Domain ? Perot-Systems8
What is lock escalation?  1
 
For more SQL Server Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com