Explain basic SQL queries with SELECT from where Order By,
Group By-Having?

Answers were Sorted based on User's Feedback



Explain basic SQL queries with SELECT from where Order By, Group By-Having?..

Answer / swapna

Order by clause is used to sort information of a table into
specific order either ascending or descending order.

syntax:select stmt order by column;

ex:select * from emp order by sal;

Group by clause is used to divide entire group into
subgroups based on the common values columns.we can use
group by clause along with group functions.

syntax:select group by(exp 1),group by(exp 2),....from
table name group by column name;
select max(sal),min(sal) from emp group by deptno;
Group by clause can allow where clause.


Having:is used to restrict information of the atble based
on condition.

syntax:select group by (exp 1) ,group by (exp 2) from table
name group by column having (condition).

Having and Group by clauses can interchange their positions.

but when using having along with order by clause having
should be placed before order by clause.

Is This Answer Correct ?    25 Yes 4 No

Explain basic SQL queries with SELECT from where Order By, Group By-Having?..

Answer / ranjan

In above select stmnt city must be in group by clause. Otherwise it'll sho error.

Is This Answer Correct ?    3 Yes 1 No

Explain basic SQL queries with SELECT from where Order By, Group By-Having?..

Answer / nitin

sory i m satisfied with idea.actualy i want to know is this
query is right or not.plz inform me.

SELECT country,city
FROM customers
GROUP BY country
ORDER BY city DESC

Is This Answer Correct ?    7 Yes 19 No

Post New Answer

More SQL Server Interview Questions

What do you mean by the term 'normalization'?

0 Answers   Tech Mahindra,


How to insert multiple rows with one insert statement in ms sql server?

0 Answers  


What are the type of Indexes? which one is best, why?

6 Answers  


sql server has its default date format in da form "yy-mm-dd" its possible to convert da current date format of sql server to desired format. Now my question is dat how to get da previous and comin days date in my desired format??

2 Answers  


What is Data model and how to prepare a data model.?

1 Answers   TCS,






how would you write a sql query to compute a frequency table of a certain attribute involving two joins? What changes would you need to make if you want to order by or group by some attribute? What would you do to account for nulls?

0 Answers   Facebook,


What are the characteristics of modern DBMS?

0 Answers   Ericsson,


How to drop an existing stored procedure in ms sql server?

0 Answers  


How To Change Column Ordinal Position in SQL Server 2005 using Query i.e I Want To Add Column at Particular Ordinal Position in SQL Server 2005

2 Answers  


How to apply cascading referential integrity in place of triggers?

0 Answers  


What are the four main query statements?

7 Answers   Wipro,


What is reference section?

0 Answers  


Categories