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

What is a bit datatype?

554


What is the difference between mysql and sql server?

464


Are there issues when exporting SSRS reports into Microsoft Excel? When my users are trying to export a SSRS report into Microsoft Excel, one or two columns in the report appear to merge together. Why might this be?

134


What is the optimization being performed in oracle and SQL Server?

614


What is SQL Azure Fabric?

92






What is a hint?

575


How to view existing indexes on an given table using sp_help?

587


Why use update_statistics command in sql server?

544


What are the limitations/drawbacks or ssrs 2008 r2?

86


What happens if null values are involved in comparison operations?

535


Explain what are the restrictions while creating batches in sql server?

571


How does the report manager work in SSRS?

114


Define left outer join?

570


What does nvl stand for?

552


Explain an automatic checkpoint

555