0% found this document useful (0 votes)
12 views6 pages

DBMS 4

The document discusses using GROUP BY, HAVING, and ORDER BY clauses in SQL queries to retrieve and analyze grouped data. It also covers COMMIT, ROLLBACK, and SAVEPOINT commands to control transactions and rollback to savepoints within transactions.

Uploaded by

pareshkumar3108
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views6 pages

DBMS 4

The document discusses using GROUP BY, HAVING, and ORDER BY clauses in SQL queries to retrieve and analyze grouped data. It also covers COMMIT, ROLLBACK, and SAVEPOINT commands to control transactions and rollback to savepoints within transactions.

Uploaded by

pareshkumar3108
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Experiment : 4.

Aim : Queries using Group By, Order By, and Having Clauses.

Description : SQL gives you options for retrieving, analyzing, and displaying the
information you need with the GROUP BY, HAVING, and ORDER BY clauses. Here are
some examples of how you can use them.
GROUP BY clauses:
Sometimes, rather than retrieving individual records, you want to know something about
a group of records. The GROUP BY clause is the tool you need. Suppose you’re the sales
manager of another location, and you want to look at the performance of your sales force.

SELECT expressions
FROM tables
[WHERE conditions]
ORDER BY expression [ ASC | DESC ];
HAVING clauses:
You can analyze the grouped data further by using the HAVING clause. The HAVING
clause is a filter that acts similar to a WHERE clause, but on groups of rows rather than
on individual rows. To illustrate the function of the HAVING clause, suppose the sales
manager considers Bennett to be in a class by himself.

SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
HAVING condition
ORDER BY column_name(s);
ORDER BY clauses:
Use the ORDER BY clause to display the output table of a query in either ascending or
descending alphabetical order. Whereas the GROUP BY clause gathers rows into groups
and sorts the groups into alphabetical order, ORDER BY sorts individual rows. The
ORDER BY clause must be the last clause that you specify in a query.

SELECT D_name, D_state, D_salary


FROM developers
ORDER BY D_state ASC;
Experiment : 4.2

Aim : Queries on Controlling Data: Commit, Rollback, and Save point.

Description : COMMIT Command:


If everything is in order with all statements within a single transaction, all changes are
recorded together in the database is called committed. The COMMIT command saves all
the transactions to the database since the last COMMIT or ROLLBACK command.

Syntax:
COMMIT;
ROLLBACK Command

If any error occurs with any of the SQL grouped statements, all changes need to be
aborted. The process of reversing changes is called rollback. This command can only
be used to undo transactions since the last COMMIT or ROLLBACK command was
issued.

Syntax for ROLLBACK command:


ROLLBACK;
SAVEPOINT Command

SAVEPOINT creates points within the groups of transactions in which to ROLLBACK.


A SAVEPOINT is a point in a transaction in which you can roll the transaction back to a
certain point without rolling back the entire transaction.

Syntax for Savepoint command:


SAVEPOINT SAVEPOINT_NAME;

You might also like