0% found this document useful (0 votes)
142 views24 pages

It - 802 - Study Material

The document provides an introduction to fundamentals of computers, including their evolution, components, characteristics, and basic functions. It discusses how computers work using binary digits and processing inputs through various units like the CPU and memory. Examples are given of different types of hardware, including input devices like keyboards and mice, output devices like monitors and printers, and storage units like RAM, ROM, and secondary storage devices. The roles of the operating system and software are also outlined.

Uploaded by

kavya shree
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)
142 views24 pages

It - 802 - Study Material

The document provides an introduction to fundamentals of computers, including their evolution, components, characteristics, and basic functions. It discusses how computers work using binary digits and processing inputs through various units like the CPU and memory. Examples are given of different types of hardware, including input devices like keyboards and mice, output devices like monitors and printers, and storage units like RAM, ROM, and secondary storage devices. The roles of the operating system and software are also outlined.

Uploaded by

kavya shree
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/ 24

INFORMATION TECHNOLOGY - 802

Fundamentals of Computer

Introduction

In today’s world we can see that almost all our work is being done with the help
of computers. Applications of computers can be seen in every electrical device
nowadays whether it is television, washing machine, watches, mobile phones
and the list is endless. With the advancement in use and technology, use of
electronic devices has increased manifold. All this is possible because of the
ease and accuracy we get with these devices. Life has taken a fast pace and
distances make hardly any difference with the help of these machines. Let us
have an insight to the basics of computers in this chapter.

Evolution of Computers

Computer is an electronic device and works on electronic signals. The on and


off signals denote 1 and 0 respectively. The binary language, also called
machine language, works on two digits 0 and 1. Earlier computer experts used
to work and give instruction in binary language only. Over the years, many user-
friendly languages similar to simple English terms have developed and every
computer programmer need not learn and give instructions in binary language.
Many user-friendly languages have been developed like C, C++, Java, JavaScript,
Python and many more. These languages are known as high level languages.
Commands given in high level languages need to be converted into binary
language with the help of translators.

The data and/or instructions given by the user to the machine are termed as
Input and the result generated by the machine after processing the data is the
Output.

Characteristics of a Computer
speed : A remarkable quality of computers is their ability to process data and
instructions at a very high speed.

Versatility: is the ability of a computer to do a variety of jobs with ease. One


moment you can type a letter using any of the available word processing
packages, and the other moment you can use the same machine to do
calculations yielding the salaries of employees of an organization.

Accuracy: Not only does the machine perform varied jobs with high speed, but
also does them with high precision and accuracy.
Memory: One of the notable features of a computer is its memory. However,
the computer’s main memory is volatile, i.e., it is lost when we switch off the
computer.
Therefore, computers are provided another form of memory that does not fade
away when it is switched off. It is called secondary memory and is available in
the form of floppy disks, pen drives, portable hard disks.

Storage: Huge amounts of data and information can be stored in a computer


for future retrieval. The human memory is limited and fades away with time,
which is not true for a computer.

Components of a Computer
The computer is the combination of hardware and software. Hardware are the
physical components of a computer like motherboard, memory devices,
monitor, keyboard etc. while software is the set of programs or instructions.
Both hardware and software together make the computer system function.

Every task given to a computer follows an Input- Process- Output Cycle (IPO
cycle). It needs certain input, processes that input and produces the desired
output. The input unit takes the input, the central processing unit does the
processing of data and the output unit produces the output. The memory unit
holds the data and instructions during the processing.

Input: To initiate the process, the computer needs to be told of the problem to
be solved. For this purpose, a set of instructions and data is provided through
the input devices such as keyboard and mouse. A set of instructions provided
to the computer for doing a task is called a program.

Storage:
Every bit of information in computer is stored in terms of Bits (Binary Digits) i.e.
0s and 1s
The smallest unit of memory is Byte. The other units of memory are
1 nibble = 4 bits
1 byte = 8 bits
1024 bytes = 1 Kilobyte (KB)

1024 KB = 1 Megabyte (MB)

1024 MB = 1 Gigabyte (GB)

1024 GB = 1 Terabyte (TB)


1024 TB = 1 Petabyte (PB)

1024 PB= 1 Exabyte(EB)


1024 EB = 1 Zettabyte(ZB)

1024 ZB = 1 Yottabyte (YB)

There are basically two types of computer storage devices:

Primary Memory : Data stored in Primary Memory is directly accessible by the


CPU. The inputs received in the above steps are stored in the computer
memory, called random access memory (RAM). This storage is relatively fast
and expensive as compared to the secondary storage.
Primary memory is directly connected to the CPU.
It is also called main memory, primary memory, or working memory of the
machine.

Primary memory is of two types :

1.RAM ( Random Access Memory) : It is a primary volatile memory i.e. its data
gets lost once the power supply is stopped.

2.ROM ( Read Only Memory) : It is generally used in startup operations of


computer. It is a non-volatile primary memory.
Secondary Storage: The memory which is external to the computer system
forms the secondary storage, for example, the magnetic tapes, compact disks,
pen drives are all examples of the secondary storage. These are not directly
connected to the CPU.

Processing: The inputs provided by the user are processed by the central
processing unit as per the specified instructions. The result of the processing is
then either directed to the output devices or to a memory location for storage.

CPU: The motherboard houses the main processor or the CPU (Central
Processing Unit). CPU executes the user instructions and coordinates amongst
all other units of the computer. Thus, it is primarily responsible for the
performance of the machine

Control Unit: is responsible for coordination between the different units of a


computer. It controls the input, processing and output operations. For
example, it coordinates with the peripheral devices to accept the input or
display the output. It is like a manager of all operations.

Arithmetic Logic Unit (ALU): is responsible for actual processing of data. It


retrieves the data from the storage unit and performs the arithmetic
calculations and/or comparisons on them and the processed data is then sent
back to the storage.
Output: The result of processing carried out by the computer is often directed
to the display device such as the monitor or printer. Other forms of devices are
not uncommon, for example, the peripherals. The major functionality in a
computer is done in the Processing Unit. Processing Unit takes input and
processes it through the set of instructions ( given in the software) for that
input and finally it gives the results to the output unit.

Input Devices
Input devices takes input from the user. The input may be in the form of text,
image, sound, video etc. a wide range of input devices have been devised for
supporting varying types of input. Following are examples of some of the input
devices of computer:

- Keyboard: this is a standard input device and takes data in the form of text.
- Mouse : it is a pointing input device.
- Webcam: it takes data in the form of video/image
- Scanner : it generally stores data in the form of graphics
- Microphone : it is used for voice input/ audio input
- Handwriting input board: it is used for giving input from

Output Devices:

Devices that are used to give output to the user. Output may be in the form
of visuals, text, audio, printout etc. different types of output devices are there
to support various types of output. Following are some examples of output
devices:

- Monitor/ VDU ( Visual Display Unit) : it is the standard output device and is
similar to a television screen.
- Speaker : it is an output device that gives output in the form of an audio/
voice.
- Printer : it is also a very commonly known output device that gives output in
the form of print out also called as hard copy.
- Plotter : it is a large printer like device that is used to take print of large maps,
architectural designs.
- Projector : it is an output device that gives an enlarged view of the output on
a large screen. It is generally used for giving a view of output to a large
audience.
Operating System :
Operating system is the software that acts as an interface between user and
computer hardware. A computer needs to communicate with both the
hardware and software.The popular operating system are Windows, Linux,
Unix, MS-DOS, SOLARIS, MAC OS

Types of Operating system


Operating systems can be classified in different ways; depending on various
parameters.

Single-tasking and Multi-tasking

Single Task Operating System : such operating systems allow execution of only
a single program at any given instant.

Multi-Tasking operating system can execute more than one program


simultaneously. The processor time, in this case, is divided amongst various
processes.

Single user and Multi-user

Single-user operating systems allow only one user to use the system. The
desktop systems can be classified as typical single user systems

Multi-user operating systems allow many users to access the system by


maintaining an account of all the registered users.

Real-Time Operating System

Operating systems which ensure that the response time is fixed are categorized
as real-time operating systems. They are intended for applications where data
needs to be processed quickly, without any significant delays

Batch Processing Systems

In a batch processing system, similar jobs are clubbed together and submitted
as a block to the processor for execution. User intervention is minimal in such
systems. The jobs are picked up one by one and executed.
Self assessment Exercises:
Define the following :
• Hardware
• Input Device
• Output Device
• Processor
• Operating System
Expand the following :
a. ALU
b. CPU
c. CU
d. RAM
e. ROM
Answer the following
a. Differentiate between RAM and ROM
b. Explain input and output devices.
c. Explain storage devices of a computer.
d. Describe secondary and primary storage devices of a computer

RELATIONAL DATABASE MANAGEMENT SYSTEM

Database Management System (DBMS)

To create and maintain a database on a computer, we need a database


program or software, called a Database management system, or DBMS.
Database Management System is a software that enables users to create
and maintain databases. The popular DBMSs are MySQL, PostgreSQL,
Microsoft Access, Oracle, Microsoft SQL Server, DB2 and Sybase.

DBMS allow us to:


· store data in a structured way.
· query the database (that is, ask questions about the data)
· sort and manipulate the data in the database
· validate the data entered and check for inconsistencies
· produce flexible reports, both on screen and on paper, that make it easy
to comprehend the information stored in the database.

Relational Database
In the database the data is organized into separate tables. Once the tables
have been set up, a relationship can be created to link them together. Such
a database that stores data in separate tables that are related through the
use of a common column is called a Relational database.

Benefits of using a DBMS are:


a. Redundancy can be controlled

b. Inconsistence can be avoided

c. Data can be shared

d. Security restrictions can be applied.

RDBMS Terminology

1. Domain

It is pool of values or the collection (set) of possible values from which the
value for a column is derived.

2. Tables or Relation in a Database

Relational Databases store data or information in tables.. A table refers to a


two-dimensional representation of data using rows and columns. The tables
in a database are generally related to each other to facilitate efficient
management of the database. Interrelated tables also reduce the chances
of errors in the database.
Tuple - The horizontal subset of the Table is known as a Row/Tuple. Each
row represents a record, which is a collection of data about a particular
entity such as person, place or thing.

Attribute - The vertical subset of the Table is known as a Column/Attribute.


The term field is also often used for column. Each column has a unique
name and the content within it must be of the same type.

Key: A column or a combination of columns which can be used to identify one


or more rows (tuples) in a table is called a key of the table.

Primary Key: The group of one or more columns used to uniquely identify
each row of a relation is called its Primary Key.

A primary key is a field in a table that is unique for each record. Every
database table should have a column or a group of columns designated as
the primary key. The value this key holds should be unique for each record
in the table. Some more examples of Primary key are: Accession Number
of a Book in the Book table, Employee ID of an employee in the Employee
Table, Item Code of an item in the Stock table, Flight Number of a flight in
the Flight Master Table, etc.

The purpose of a primary key is to uniquely identify each record in a table.

Candidate Key: A column or a group of columns which can be used as the


primary key of a relation is called a Candidate key because it is one of the
candidates available to be the primary key of the relation.

In a table, there may be more than one field that uniquely identifies a record.
All such fields are called candidate keys. A Candidate key is an attribute (or
set of attributes) that uniquely identifies a row. A Primary Key is one of the
candidate keys. A table may have more than one candidate keys but
definitely has one and only one primary key.

Alternate Key: A candidate key of a table which is not selected as the primary
key is called its Alternate Key.

Example: Consider the following Table, RollNo and Admission_no both


may be used to uniquely identify each row in this Table, so both are
candidate keys.
Candidate keys which are not made primary key are called Alternate
keys. In the above example, if we use one of the candidate keys, say,
Admission No as the Primary Key, the other Candidate Key Roll No is the
Alternate Key and vice-versa.
Foreign Key: A primary key of a base table when used in some other table
is called as Foreign Key. The primary key column and the foreign key
column must have the same data type and size.

Introduction to MySQL:

MySQL is a relational database management system (RDBMS). It is


pronounced as "My Sequel". MySQL was originally founded and developed
in Sweden by David Axmark, Allan Larsson and Michael Widenius, who had
worked together since the 1980s.

Characteristics of MySQL:

MySQL is released under an open-source license so it is customizable.

It requires no cost or payment for its usage.


MySQL has superior speed, is easy to use and is reliable.
MySQL uses a standard form of the well-known ANSI-SQL standards.
MySQL is a platform independent application which works on many
operating systems like Windows, UNIX, LINUX etc. and has compatibility
with many languages including JAVA , C++, PHP, PERL, etc.
MySQL is an easy to install RDBMS and is capable of handling large data
sets.

Categories of SQL Commands


SQL commands can be classified into the following categories:
1. Data Definition Language (DDL) Commands
The DDL part of SQL permits database tables to be created or deleted.
It also defines indices (keys), specifies links between tables, and
imposes constraints on tables. Examples of DDL commands in SQL
are:

CREATE DATABASE - creates a new database


CREATE TABLE - creates a new table
ALTER TABLE - modifies a table
DROP TABLE - deletes a table

2. The Data Manipulation Language (DML) Commands


The query and update commands form the DML part of SQL: Examples of
DDL commands are:

SELECT - extracts data from a table


UPDATE - updates data in a table
DELETE - deletes data from a table
INSERT INTO - inserts new data into a table

MySQL Data Types


Data Types. They indicate the type of data that you are storing in a given
table column. So, what are the different Data Types available in MySQL?
Here is a list of some of the most common ones and what type of values
they hold:

Class Data Type Description Example


Text CHAR(size) A fixed-length string from 1 to 'Maths'
255 characters in length "TexT"
with spaces to the specified
length when stored.
Values must be enclosed in
single quotes or double
quotes

Text VARCHAR(size) A variable-length string from 'Computer'


1 to 255 characters in length; "good morning"
i.e. VARCHAR(25). Values
must be
enclosed in single quotes or
double quotes.
Numeric DECIMAL(size,d) It can represent number with 17.32
or without the fractional part. 345
The maximum number of
digits may be specified in the
size parameter. The
maximum number of digits to
the right of the decimal point
is specified in the d
parameter
Numeric INT Or INTEGER It is used for storing integer . 76
values. You can specify a
width upto 11
Date DATE It represents the date '2009-07-02’
including day, month
and year
Time TIME It represents time. '23:59:59'
Format: HH:MM:SS '23:59:59'

Creating a Database
Before creating a table we will first create a database. To create a database
we will give

CREATE DATABASE command.


syntax:-CREATE DATABASE <database name>;
mysql> CREATE DATABASE School;

Once the above-mentioned statement gets executed, a database with the


name School is created on system. You may give any name of the
database . Now to open the database to work USE statements are
required. Semicolon is standard way to end SQL statement

Using a database

Syntax: USE <databasename>;


mysql> USE School;
Database Changed

Viewing the current database


We must know which database we are currently working in, to see
the name of the current database we use SELECT command.
Syntax: SELECT DATABASE(); School will be displayed.

Creating a Table
After creating a database, the next step is creation of tables in the database.
For this CREATE TABLE statement is used.

Syntax:
CREATE TABLE <TableName>(<ColumnName1> <Data Type1>,
<ColumnName2> <Data Type2>,… ,<ColumnNameN> <Data TypeN>);

Adding constraints in table


Many times it is not possible to keep a manual check on the data that is
going into the tables. The data entered may be invalid. MySQL provides
some rules, called Constraints, which help us, to some extent, ensure
validity of the data. These constraints are:

Constraint Purpose
Primary Key Sets a column or a group of columns as a
primary key of the table. Therefore, NULLs
and Duplicate values in this column are not
accepted.
NOT NULL Makes sure that NULLs are not accepted in
the specified column.
DEFAULT Gives default value if the user does not give
the value in the specified column

UNIQUE Make sure that duplicate values in the


specified column are not accepted.

EXAMPLE:

CREATE TABLE Shoes


(Code CHAR(4) PRIMARY KEY,
Name VARCHAR(20),
type VARCHAR(10),
size INT(2) NOT NULL,
cost DECIMAL(6,2),
margin DECIMAL(4,2),
Qty INT(4));

Viewing the tables in the database


To see a list of tables present in the current database we
will use SHOW TABLES.
Syntax: SHOW TABLES;
mysql> SHOW TABLES;

Viewing the structure of the table


The DESCRIBE statement can be used to see the structure of a table as
indicated in the Create Statement. It displays the Column names, their data
types, whether Column must contain data, whether the Column is a Primary
key.
Syntax:
DESCRIBE <table name>;
A constraint is shown beside the column name on which it is applicable.
E.g., the statement: DESC Shoes;
displays the table structure as follows:
+--------+-----------------------+-------+-------+---------+---------
| Field | Type | Null | Key | Default | Extra |
+--------+-----------------------+---------+-----+---------+--------
| Code | CHAR(4) | NO | PRI | NULL | |
| Name | VARCHAR(20) | YES | | | |
| type | VARCHAR(10) | YES | | NULL | |
| size | INT(2) | NO | |0 | |
| cost | DECIMAL(6,2) | YES | | NULL | |
| margin | DECIMAL(4,2) | YES | | NULL | |
| Qty | INT(4) | YES | | NULL | |
INSERT COMMAND

After creating database and relations, we can add data in the relations.
INSERT INTO command is used to enter values in a table. Syntax of insert
command is as follows :

INSERT INTO <TABLENAME >(COLUMN NAMES>) VALUES (value1,


value2, value3,……)

INSERT command is used in various ways to insert values within a table.


Following points should be kept in mind while inserting records in a
relation. : - Numeric values may be entered as numerals
- string must be enclosed in single/ double quotes
- Date should be entered in single/double quotes in format ‘yyyy-mm-dd’
- NULL value should be entered as NULL without any quotes. NULL value
means blank value in the table.

Main purpose after storing the data in a table is to retrieve the data for
generating various reports. Data from tables can be retrieved/ fetched using
Select Command.

SELECT COMMAND :
SELECT command is used to view the data from a relation in a database. It
returns a result set of data/ records from one or more relations.
Syntax of SELECT Command :
SELECT <column name> FROM <table name >;
Command to retrieve
single column display
select Rno from
STUDENT;

mysql> select rno from student;

+---------- +

| r no |

+---------- +

| 1|

| 2|

The above command displays only the roll numbers of students.

Command to display multiple columns :


Select Rno, gender , Fname from Student;
Above command fetches the result set having roll number, first name and
gender of students and displays the list on screen as follows :

The output displayed the data in same order as the order of columns given
in the command.

Command to display all the columns : ‘* ‘ symbol is used to display all the
columns of the table. Select * from Student;

* is the wild card character ( means ALL) that is used to display names of
all the columns.

DISTINCT ( Displaying values without repetition)

If a column contains repeated values then the select statement gives the
result set with repeated values like if a command is given to display
DISTINCT keyword is used to eliminate repeated values

Consider the query: Select marks from student: mysql> select marks from student;

+---------+

| marks |

+---------+

| 98 | | 92 | | 95 | | 94 || 93 | | 84 | | 84 || NULL |
+---------+

8 rows in set (0.00 sec)

In above example it can be noticed that value 84 appears twice.


When duplicate value appears only one instance of the value is considered
and is displayed.

For example :

Select DISTINCT marks from student;

+---------+

| marks |

+---------+

| 98 | | 92 | | 95 | | 94 | | 93 | | 84 || NULL |

+---------+

7 rows in set (0.00 sec)

A number of keywords and clauses are used with SELECT statement to


retrieve data as per the requirement. These are discussed below:

ALL
Keyword ALL when used with Select statement is used to display values of
all columns in the row. It displays even the duplicate values.

WHERE Clause

Where clause is used to fetch data based on a criteria/ condition. Criteria


can be given using an expression. Table has many records in it and it is not
always desirable to show all the records every time. At times only certain
set of specific rows need to be displayed. based on the criteria. Keyword
WHERE is used for selection of rows with select statement. We can also
say that WHERE clause is used to filter records. It is used to fetch only
those records that satisfy a specified criterion.

Syntax:

SELECT <column name1> [,<column name> ,….] FROM


<table name> WHERE <condition>;

For example if we wish to display records of students who have a got marks
greater than we will 90 then following command needs to be entered:
mysql> select fname, marks from student where marks > 90;

Use of arithmetic operators


SQL supports a set of arithmetic operators that can be used .in select query.
Arithmetic operators are used with numeric values. Following is the set of
arithmetic operators supported by SQL:

Operator Description
+ For addition of values
- Subtraction of values
* For finding the product of values
/ Divide
% Modulo operator. Returns the remainder

Following set of examples show the use of arithmetic operators for


performing calculations :

Arithmetic operators are used to perform calculations over the numeric


fields of a table. For example, if we wish to see the result after adding
10 marks for activity in each record then what would be the total then
this can also be done using expression as shown below:

mysql> select fname, marks + 10 from student

-> where marks > 90;


+--------------------------- +-------+

| fname | marks |

+----------------------------+--------+

| ABHISHEK | 108 |

| BHISHEK | 102 |

| BHUSHAN | 105 |

| CHETALI | 104 |

| CHETANYA | 103 |

+-----------------------------+---------+

5 rows in set (0.11 sec)

Another example: in case to view the salary of employees after adding a


bonus of 10 percent to the salary , following command may be used:

mysql> select empname, salary+salary*0.1 from employee where designation


’manager’;

+------------------- +---------------------------+
| empname | salary+salary*0.1 |
+--------------------+---------------------------+
| ABHINAV | 69803.20 |
| VISHESH | 49290.70 |
| B.RATNAKAR | 118982.95 |
| CHETANYA | 198675.45 |
| SOURABH | 99456. 93 |
+-----------------------+-------------------------+
5 rows in set (0.11 sec)

Note that the calculations done on column values only appear on the
output screen and does not make any changes in the records of the table.
The values remain the same in table. Actually the operation is performed
over the result set and not on the actual table. For making any changes
within a UPDATE command that is discussed after this topic.

Relational Operators

Relational Operators compare two values and gives a result in the form of
true of false. Every row is filtered using the relational operator in the
expression in where clause. Given below are the relational operators used
in MySQL alongwith their functions:

These operators are of great help to fetch data on a particular criteria. If we


need to display data of all the employees who belong to city ‘Jaipur’ then
following command may be given :

mysql> select name from employee where city =’Jaipur’

mysql> select empname from employee where esal<50000.00;

mysql> select empname from employee where edept<>'Sales';


Logical Operators
SQL supports following set of logical operators:
AND, OR, NOT
AND Operator is used with where clause and returns true if both the
conditions are true. Those records are displayed which are true for both the
conditions.
for example:
mysql> select fname from student where gender ='f' and marks>90;

AND operator can be used to fetch records satisfying in a range of


values as shown in the example given below:
mysql> select fname, lname, marks
FROM student
WHERE marks >= 92 and marks<= 95;
In the above query, the output will display records of all the students who
have marks greater than or equal to 92 and less than or equal to 95. Similar
result can be obtained using keyword
BETWEEN .

BETWEEN operator
Keyword BETWEEN is used to fetch data based on a range of values on a
column. The result set includes the values of the upper and lower bound
given in the range.
For example , following command displays firstname, last name and marks
of the students whose marks are from 92 to 95;
mysql> select fname, lname, marks
FROM student
WHERE marks BETWEEN 92 and 95;
Output will be :
OR operator returns True if either one of the conditions is True.

For example : to view list of all the sports coach who give coaching for either
football or hockey;
mysql> select Coachname, game from Sports

where game=’football’ or game=’hockey’;

Coachname Game

Birender Singh Hockey


Jasvinder Pal Football
Dharmender Hockey

NOT Operator
Not is used for negation. It returns the result set that is opposite to the
given condition For example : following command displays name and
salary of employees whose salary is not less than 50000.00

mysql>select empname, esal from employee where NOT(esal<50000.00);

Following command displays name and zone of employees who are not in
north zone:
mysql>select empname, zone from employee where NOT(zone=’North’);

HANDLING NULL Values


IS operator is used to match NULL value in the expression.
For example, following command is to display the records with NULL values
in column edesig from table employee
mysql>select empname, zone from employee where zone IS NULL;

IS operator is used to compare equality with NULL whereas IS NOT may


be used for comparing the values not equal to NULL;

mysql> select empname, zone from employee where zone IS NOT NULL;

Note: the operations = NULL and <> NULL are not defined!

LIKE keyword
LIKE is used for pattern matching and is very useful. Following characters
used for applying pattern matching:
% percent symbol is used to match none or more characters
_ underscore character is used to match occurrence of one character
in the string

For example : To search for records having first name starting with letter ‘R’;

mysql>select * from student where fname like ‘A%’;


output:

Command to display names that end with letter ‘K’ is

mysql>select * from student where fname like ‘%K’;


Command to display list of all the students whose name has upto five
characters:

mysql>select * from student where fname like ‘_ _ _ _ _’;

Following command displays list of students whose name starts and ends
with a specified letter.
Notice that in case no record matches the given pattern then the query
returns empty set on execution.
Similarly many more patterns may be given as follows :
‘_ _ _ _’ matches any string with exactly four characters
‘S_ _ _ _’ matches any string of length of exactly 5 characters and starts with letter ‘S’
‘S_ _ _ %’ matches any string of length of 4 or more characters and starts with letter ‘S’
‘_ _ _H matches any string of length of exactly 4 characters and terminates with letter
‘_ _ _ %’ matches any string with at least three or more characters
‘%in% matches any string which containing ‘in’

ORDER BY
The result set fetched by the query can be displayed in sorted order. The
sorting can be on the basis of any particular column from the table using
ORDER BY clause.
Syntax is :
SELECT <column name>, [<column name >…]
FROM <table name>
[ WHERE <condition> ]
ORDER BY < column name> [DESC];
By default the records are displayed in ascending order of the column
name. Keyword ASC is used with ORDER BY clause for displaying the list
in ascending order and keyword DESC is used with ORDER BY clause to
display the records in descending order.

Following commands are used to display records in sorted order of marks


of students mysql>select fname, lname, marks
from STUDENT order by marks;

It can be observed that the output is displayed in the sorted order of marks.
NULL value is displayed first and records are displayed in ascending order.
Following command displays the records in descending order of fname:
mysql> select fname, lname from STUDENT ORDER BY name DESC;
ORDER By clause can be used to sort the records on the basis of two
columns also. Following command displays the result based on order of
marks and then on fname.

You might also like