DBS 09

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 16

Lecture – 15 -16

Database Systems
23 BS Cyber Security – Second Semester

By: Engr. Athar Ali, Lecturer, CSE-MUET


Contents

• DQL Statements in SQL


CATEGORIES OF SQL STATEMENTS

1.Data Definition Languages (DDL).

2.Data Query Languages (DQL).


3.Data Manipulation Languages (DML).

4.Data Control Languages (DCL).

5.Transaction Control Languages (TCL).


DATA Query LANGUAGES (DQL)

DQL statements are used for performing queries on the data within schema objects.

it is defined as a component of SQL statement that allows getting data (Data Retrieval ) from the
database and imposing order upon it.

This command allows getting the data out of the database to perform operations with it.

SELECT statement is a type of Data Query Language (DQL used to fetch


information from a database.

When a SELECT is fired against a table or tables the result is compiled into a further temporary table,
which is displayed or perhaps received by the program i.e. a front-end.
SELECT COMMAND

The SELECT Statement in SQL is used to retrieve or fetch data from a database.

We can fetch either the entire table or according to some specified rules.

The data returned is stored in a result table.

With the SELECT clause statement, we specify the columns that we want to be
displayed in the query result and, optionally, which column headings we prefer to
see above the result table.
SELECT COMMAND (Cont’d)

Syntax:
SELECT column1,column2 FROM table_name ;
Here, column1 , column2: names of the fields of the table, and table_name: from
where we want to apply query

This query will return all the rows in the table with fields column1 and column2.
SELECT COMMAND (Cont’d)

Suppose we have above table in our database, and we want to retrieve a particular record.
We may use SELECT statement differently to retrieve record and later may apply required operation.
SELECT All RECORDS

1. Select all record available in the table.

SELECT * FROM Customer;


asterisks represent all attributes of the table. This querry will retrieve all attributes available in database.
SELECT COLUMNS

2. Select a specific column or multiple columns in the table

SELECT CustomerName, LastName FROM Customer;


This query will retrieve columns named as Customer Name and LastName in the table.
CLAUSES IN DQL

Clauses are keywords that are used to filter out values available in the records.

These are used along with DQL and DML queries and pinpoint exact value that the user wants to
retrieve.

There various clauses available that include


• WHERE clause
• ORDER BY clause
• GROUP BY clause
• HAVING clause
SELECT WITH WHERE CLAUSE

WHERE clause is used with the SELECT and DML statements to select, update or delete the
data from a table on the basis of a condition.

WHERE clause selects, deletes, or updates only those rows in which expressions evaluates to
true.
SELECT column_name from table_name
WHERE column_name/expression operator value/expression;

SELECT CustomerName FROM Customer WHERE Age = '21';


SELECT WITH WHERE CLAUSE

SELECT CustomerName , FROM Customer


WHERE age = 'manager’;

SELECT CustomerName , FROM Customer


WHERE age = 21;

SELECT CustomerName , FROM Customer


WHERE LastName = ‘THAKUR’ ;
ORDER By clause

The ORDER BY clause is used to sort the rows that are retrieved from the query.

If you are using ORDER BY clause then it must be the last clause of the query.

You can specify an expression, or an alias, or column position in the sort condition.

ORDER BY Specifies the order in which the retrieved rows are displayed.

ASC Orders the rows in ascending order (Default)


DESC Orders the rows in descending order
ORDER BY clause

Syntax: SELECT column_name FROM table_name ORDER BY column_name


DESC | ASC

SELECT * FROM Customer ORDER BY Age DESC;


Task A
Retrieve data from the following table as per following parameters.
• All available records
• An attribute having country as name
• Record of customer having Shubham as name
• Record of the customer senior most customer
• Record of the customer residing in Spain
• Sort the LastName in Descending order
That’s All

You might also like