0% found this document useful (0 votes)
40 views11 pages

Structured Query Language (SQL)

Notes for computers

Uploaded by

Rafia Khan
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)
40 views11 pages

Structured Query Language (SQL)

Notes for computers

Uploaded by

Rafia Khan
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/ 11

STRUCTURED QUERY LANGUAGE (SQL)

❖ Single Row Functions


These are also known as Scalar functions. Single-row functions are applied on a
single value and return a single value.

1. Numeric/Math functions- Math functions accept numeric values as input, and


return a numeric value as a result.
ROUND()

Decimal places position value is rounded to the next integer if its next right side number
is>=5 Default decimal place is 0 position if we do not specify

2. Date and time functions accept date and time values as input, and return
numeric or string, or date and time values as output.
3.String functions accept character values as input, and return either
character or numeric values as output.
❖ Aggregate functions are also called multiple-row functions. These functions
work on a set of records as a whole and return a single value for each column of
the records on which the function is applied.
❖ GROUP BY in SQL -At times we need to fetch a group of rows on the basis of
common values in a column. This can be done using a GROUP BY clause. It
groups the rows together that contain the same values in a specified column.

HAVING Clause in SQL is used to specify conditions on the rows with GROUP
BY clause.

WHERE is applied before GROUP BY, and HAVING is applied after.


ORDER BY clause is used to sort the table data in either Ascending order or
Descending order. Ascending order is the default.

Ascending- select * from student order by class;

Descending- select * from student order by class desc;


Eg1)
Suppose we have a student table with the following data.

Now we write query–select class,avg(marks) from student where class<10 group


by class order by marks desc;

Query results will be unique occurrences of class values where class<10 along
with average marks of each class(subgroup) and descending order of marks.

Eg2)
we are having a student table with the following data.

Now we write query–select class,avg(marks) from student group by class having


avg(marks)<90;

Query result will be unique occurrences of class values along with average
marks of each class(sub group) and each class having average marks<90.
LIKE

1. Query- Display details of teacher whose name begins with S.


Ans-
select * from teacher where name like “S%”;

2. Query- Display details of teacher whose name has S in it.


Ans-
select * from teacher where name like “%S%”;

3. Query- Display details of teacher whose name ends with S.


Ans-
select * from teacher where name like “%S”;

4. Query- Display details of teacher whose name contains S as second character.


Ans-
select * from teacher where name like “_S%”;

DISTINCT
The SELECT (DISTINCT column name) statement is used to return only distinct
(different) values.

Inside a table, a column often contains many duplicate values; and sometimes you only
want to list the different (distinct) values.

Query- Count different types of rooms available in the Hotels.


Ans-
select count(distinct room_type) from HOTEL;

NOT IN
Query- Display the details of FANS who do not belong to AJMER
Ans-
select * from FANS where FAN_CITY not in “AJMER”;

IS NULL
Query- Retrieve all details from table where customer has no accumulated amount.
Ans-
select * from CUSTOMER_DETAILS where ACCUMLT_AMT is NULL;
IN
Query- count number of students who have either accounts or informatics as subjects.
Ans-
select count(*) from STUDENT where SUBJECT in(“ACCOUNTS”,”INFORMATICS”)

BETWEEN to access data in specified range


mysql> SELECT * FROM Student WHERE class between 4 and 6;
A database is a collection of DATA/INFORMATION that is organized so that it can be
easily accessed, managed and updated.

NEED OF DBMS
● To manage large chunks of data
● Ease of updating data
● Security of Data

A DBMS refers to a software that is responsible for storing, maintaining and utilizing
database in an efficient way.

A Database along with DBMS software is called Database System.

ADVANTAGES OF DBMS:
● Reduces redundancy
● Facilitates sharing of data
● Ensures security

A relational database is a collective set of multiple data sets organized by tables,


records and columns. SQL supports relational database.

● Column – Attributes – Degree


● Rows – Tuples – Cardinality
TYPES OF KEYS IN DBMS

Primary Key – A primary is a column or set of columns in a table that uniquely


identifies tuples (rows) in that table.
Candidate Key –It is an attribute or a set of attributes or keys participating for Primary
Key, to uniquely identify each record in that table.
Alternate Key – Out of all candidate keys, only one gets selected as primary key,
remaining keys are known as alternate or secondary keys.
Foreign Key – Foreign keys are the columns of a table that points to the primary key of
another table. They act as a cross-reference between tables.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy