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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do I save a stored procedure in sql server?

497


Explain different types of lock modes in sql server 2000?

525


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

639


Can coalesce return null?

549


Does server sql treat char as a variable-length or fixed-length column?

589






Explain the first normal form(1nf)?

563


What is the default fill factor value?

587


What happens if the update subquery returns multiple rows in ms sql server?

593


Explain different types of Normalization.

601


What is the command to change the recovery model?

571


What are the differences between DDL, DML and DCL in SQL?

758


How to see existing views in ms sql server?

551


explain how to create a new schema in a database? : Sql server database administration

584


Explain how to maintain a fill factor in existing indexes?

530


What are date and time data types in ms sql server?

531