Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 53

PRACTICAL FILE

ON
“DATABASE MANAGEMENT SYSTEM”

SUBMITTED TO: SUBMITTED BY:


MRS. HEENA BHALLA ANUJ SHARMA

KAMAL INSTITUTE OF HIGHER EDUCATION AND ADVANCED TECHNOLOGY

K-1 EXTENSION, MOHAN GARDEN, NEW DELHI


-110059
(AFFILIATED TO GGSIPU, DELHI)
BATCH (2018-2021)
INDEX

S.N TOPIC PAG TEACHER’S


O E SIGN.
NO.
1 INTRODUCTION TO SQL 1-5

2 DATABASE 5

3 WHAT IS DBMS? 6

4 CHARACTERISTICS OF DBMS 6

5 TYPES OF DBMS 6-7

6 DATATYPE 7-8

7 SQL COMMANDS 9-11

8 CREATE DATABASE-DDL 12

9 USE DATABASE-DDL 12

10 12
CREATE TABLE-DDL
11 13
ALTER TABLE-DDL
12 13
DROP TABLE-DDL
13 14
DROP COLUMN-DDL
14 14-15
INSERT-DML
15 15-16
UPDATE-DML
16 16
DELETE-DML
17 17
SELECT-DML
18 17-19
DIFFERENCE BETWEEN DESCRIBE AND
SELECT
19 19-21
DIFFERENCE BETWEEN ALTER AND UPDATE
20 21-22
DIFFERENCE BETWEEN DROP AND DELETE
21 23
COUNT
22 SUM 23

23 AVERAGE 24

24 MIN 24

25 MAX 24-25

26 FIRST 25-26

27 LAST 26-27

28 GROUP BY CLAUSE 27-28

29 ORDER BY CLAUSE – ASCENDING ORDER 29-31

30 DESCENDING ORDER 31-32

31 WHERE CLAUSE 32-33


32 HAVING CLAUSE 33-34

33 DIFFERENCE BETWEEN HAVING AND 34-35


WHERE CLAUSE
34 35
PRIMARY KEY
35 35-36
FOREIGN KEY
36 36
NOT NULL
37 37
LOGICAL OPERATOR – LIKE
38 38
BETWEEN
39 38-39
AND
40 39-40
OR
41 40-41
IN
42 41-42
COMPARISON OPERATOR
43 42
EQUALS TO
44 42
GREATER THAN
45 43
LESS THAN
46 44
GREATER THAN EQUALS TO
47 44
LESS THAN EQUALS TO
48 44-45
NOT EQUAL TO
49 45
JOIN
50 45-46
INNERJOIN
51 46-47
LEFT OUTER JOIN
52 47-48
RIGHT OUTER JOIN
INTRODUCTION TO
SQL
What is SQL?

SQL is a language to operate databases; it includes database creation, deletion,


fetching rows, modifying rows, etc. SQL is an ANSI (American National Standards
Institute) standard language, but there are many different versions of the SQL
language. Structured Query Language (SQL) is a standard computer language
for relational database management and data manipulation. SQL is used to
query, insert, update and modify data. Most relational databases support SQL,
which is an added benefit for database administrators (DBAs), as they are often
required to support databases across several different platforms. First developed
in the early 1970s at IBM by Raymond Boyce and Donald Chamberlin, SQL was
commercially released by Relational Software Inc. (now known as Oracle
Corporation) in 1979. The current standard SQL version is voluntary, vendor-
compliant and monitored by the American National Standards Institute (ANSI).
Most major vendors also have proprietary versions that are incorporated and
built on ANSI SQL, e.g., SQL*Plus (Oracle), and Transact SQL (T-SQL) (Microsoft).
One of the most fundamental DBA rites of passage is learning SQL, which begins
with writing the first SELECT statement or SQL script without a graphical user
interfaces (GUI). Increasingly, relational databases use GUIs for easier database
management, and queries can now be simplified with graphical tools, e.g., drag-
and-drop wizards. However, learning SQL is imperative because such tools are
never as powerful as SQL.

SQL code is divided into four main categories:

• Queries are performed using the ubiquitous yet familiar SELECT statement,
which is further divided into clauses, including SELECT, FROM, WHERE and
ORDER BY.
• Data Manipulation Language (DML) is used to add, update or delete data and
is actually a SELECT statement subset and is comprised of the INSERT, DELETE
and UPDATE statements, as well as control statements, e.g., BEGIN
TRANSACTION, SAVEPOINT, COMMIT and ROLLBACK.
• Data Definition Language (DDL) is used for managing tables and index
structures. Examples of DDL statements include CREATE, ALTER, TRUNCATE and
DROP.
• Data Control Language (DCL) is used to assign and revoke database rights and
permissions. Its main statements are GRANT and REVOKE.

Why SQL?

SQL is widely popular because it offers the following advantages –


• Allows users to access data in the relational database management systems.
• Allows users to describe the data.
• Allows users to define the data in a database and manipulate that data.
• Allows to embed within other languages using SQL modules, libraries & pre-
compilers.
• Allows users to create and drop databases and tables.
• Allows users to create view, stored procedure, functioning a database.
• Allows users to set permissions on tables, procedures and views.

USE OF SQL:

Essentially, Structured Query Language (SQL) is used to retrieve data or


otherwise interface with a relational database. As a standard going back
to the 1970s, SQL is a popular way to get information out of relational
database systems. Relational databases are set up with a particular
structure – each record has a series of keys that are linked to one
another in consistent ways, and placed in a "table" represented visually in
a grid.
The SQL language is written to comb the contents of tables in a
conventional database. SQL is widely used in business and in other types
of database administration. It is the default tool for “operating” on the
conventional database, to alter tabled data, retrieve data or otherwise
manipulate an existing data set.
Simple SQL commands like SELECT, ORDER BY and INSERT (all of
which are typically rendered in all capital letters) help administrators to
route data in and out of a database table. This goes on over all sorts of
platforms, and is a major part of delivering data results in today’s cloud
and hybrid distributed systems. In the API economy, where so many
pieces of “middleware” or connecting pieces join parts of an IT
architecture, having SQL as a consistent database language has been
central to porting data to all of those places that it needs to go. Because
of the fairly straightforward syntax and ease of use, administrators can
then focus on the theory of database construction and the logistical
aspect of getting data into and out of systems.
Over time, an alternative to SQL has emerged called NoSQL. The
concept is that data that is not tabled in a relational database may not
need SQL as a query language. So the biggest uses of SQL are in a
spectrum that might be called “smaller” database systems. Another way
to explain this is that SQL does not “scale infinitely.” So by that principle,
the SQL is used for traditional DB systems and other methods are used
for larger NoSQL database systems where checks on data are not strictly
enforced.

HOW TO OPEN SQL?

From the Windows Start menu, point to Programs, point to


Microsoft SQL Server, and then click SQL Server Service Manager to
ensure that the SQL Server service is running on your computer. Set the
Server property to the name of your computer, and set the Services
property to MSSQLServer.
LATEST VERSION OF SQL

Microsoft SQL Server 2019


The current version is Microsoft SQL Server 2019, released November
4, 2019. The RTM version is 15.0. 2000.5.
...
As of July 2019, the following versions are supported by Microsoft:
 SQL Server 2012.
 SQL Server 2014.
 SQL Server 2016.
 SQL Server 2017.
 SQL Server 2019.

EXPLAIN DATABASE?

A database is a data structure that stores organized information. Most


databases contain multiple tables, which may each include several different
fields. For example, a company database may include tables for products,
employees, and financial records. Each of these tables would have different
fields that are relevant to the information stored in the table.

Nearly all e-commerce sites uses databases to store product inventory and


customer information. These sites use a database management system
(or DBMS), such as Microsoft Access, FileMaker Pro, or MySQL as the "back
end" to the website. By storing website data in a database, the data can be
easily searched, sorted, and updated. This flexibility is important for e-
commerce sites and other types of dynamic websites.
Early databases were relatively "flat," which means they were limited to
simple rows and columns, like a spreadsheet. (See also "flat file database").
However, today's relational databases allow users to access, update, and
search information based on the relationship of data stored in different
tables. Relational databases can also run queries that involve multiple
databases. While early databases could only store text or numeric data,
modern databases also let users store other data types such as sound clips,
pictures, and videos.

WHAT IS DBMS (DATABASE MANAGEMENT SYSTEM)?

Database Management System (DBMS) is a software for storing and


retrieving users' data while considering appropriate security measures. It
consists of a group of programs which manipulate the database. The DBMS
accepts the request for data from an application and instructs the operating
system to provide the specific data. In large systems, a DBMS helps users
and other third-party software to store and retrieve data.

DBMS allows users to create their own databases as per their requirement.
The term “DBMS” includes the user of the database and other application
programs. It provides an interface between the data and the software
application.

Characteristics of Database Management


System
 Provides security and removes redundancy
 Self-describing nature of a database system
 Insulation between programs and data abstraction
 Support of multiple views of the data
 Sharing of data and multiuser transaction processing
 DBMS allows entities and relations among them to form tables.
 It follows the ACID concept ( Atomicity, Consistency, Isolation, and
Durability).
 DBMS supports multi-user environment that allows users to access and
manipulate data in parallel.

Types of DBMS
Hierarchical DBMS

In a Hierarchical database, model data is organized in a tree-like structure.


Data is Stored Hierarchically (top down or bottom up) format. Data is
represented using a parent-child relationship. In Hierarchical DBMS parent
may have many children, but children have only one parent.

Network Model

The network database model allows each child to have multiple parents. It
helps you to address the need to model more complex relationships like as
the orders/parts many-to-many relationship. In this model, entities are
organized in a graph which can be accessed through several paths.

Relational model

Relational DBMS is the most widely used DBMS model because it is one of
the easiest. This model is based on normalizing data in the rows and
columns of the tables. Relational model stored in fixed structures and
manipulated using SQL.

Object-Oriented Model

In Object-oriented Model data stored in the form of objects. The structure


which is called classes which display data within it. It defines a database as
a collection of objects which stores both data members values and
operations.

EXPLAIN DATA TYPE?


A data type, in programming, is a classification that specifies which type of value a
variable has and what type of mathematical, relational or logical operations can be
applied to it without causing an error. A string, for example, is a data type that is used
to classify text and an integer is a data type used to classify whole numbers.
Data Type Used for Example

String Alphanumeric characters hello world, Alice, Bob123

Integer Whole numbers 7, 12, 999

Float (floating point) Number with a decimal point 3.15, 9.06, 00.13

Character Encoding text numerically 97 (in ASCII, 97 is a lower


case 'a')

Boolean Representing logical values TRUE, FALSE

The data type defines which operations can safely be performed to create, transform
and use the variable in another computation. When a program language requires a
variable to only be used in ways that respect its data type, that language is said to
be strongly typed. This prevents errors, because while it is logical to ask the computer
to multiply a float by an integer (1.5 x 5), it is illogical to ask the computer to multiply a
float by a string (1.5 x Alice). When a programming language allows a variable of one
data type to be used as if it were a value of another data type, the language is said to
be weakly typed.

Technically, the concept of a strongly typed or weakly typed programming language is


a fallacy. In every programming language, all values of a variable have a static type --
but the type might be one whose values are classified into one or more classes. And
while some classes specify how the data type’s value will be compiled or interpreted,
there are other classes whose values are not marked with their class until run-time.
The extent to which a programming language discourages or prevents type error is
known as type safety.
SYSTEM QUERY LANGUAGE COMMANDS:

Structured Query Language (SQL) as we all know is the database language


by the use of which we can perform certain operations on the existing
database and also we can use this language to create a database. SQL
uses certain commands like Create, Drop, etc. to carry out the required
tasks.
These SQL commands are mainly categorized into four categories as:
1. DDL – Data Definition Language
2. DQL – Data Query Language
3. DML – Data Manipulation Language
4. DCL – Data Control Language

Though many resources claim there to be another category of SQL


clauses  TCL – Transaction Control Language. So we will see in detail
about TCL as well.
1. DDL (Data Definition Language):  DDL or Data Definition Language
actually consists of the SQL commands that can be used to define the
database schema. It simply deals with descriptions of the database
schema and is used to create and modify the structure of database
objects in the database.

Examples of DDL commands:


 CREATE  – is used to create the database or its objects (like
table, index, function, views, store procedure and triggers).
 DROP  – is used to delete objects from the database.
 ALTER-is used to alter the structure of the database.
 TRUNCATE–is used to remove all records from a table,
including all spaces allocated for the records are removed.
 COMMENT  –is used to add comments to the data dictionary.
 RENAME  –is used to rename an object existing in the database.
2. DQL (Data Query Language):

DML statements are used for performing queries on the data within
schema objects. The purpose of DQL Command is to get some
schema relation based on the query passed to it.

Example of DQL:

 SELECT  – is used to retrieve data from the database.

3. DML (Data Manipulation Language):  The SQL commands that deals


with the manipulation of data present in the database belong to DML
or Data Manipulation Language and this includes most of the SQL
statements.

Examples of DML:

 INSERT  – is used to insert data into a table.


 UPDATE  – is used to update existing data within a table.
 DELETE  – is used to delete records from a database table.
4. DCL (Data Control Language):  DCL includes commands such as
GRANT and REVOKE which mainly deals with the rights, permissions
and other controls of the database system.

Examples of DCL commands:

 GRANT-gives user’s access privileges to database.


 REVOKE-withdraw user’s access privileges given by using the
GRANT command.

5. TCL(transaction Control Language) :  TCL commands deals with


the  transaction within the database.

Examples of TCL commands:


 COMMIT– commits a Transaction.
 ROLLBACK– rollbacks a transaction in case of any error occurs.
 SAVEPOINT–sets a savepoint within a transaction.
 SET TRANSACTION–specify characteristics for the transaction.

DDL (DATA DEFINTION LAGUAGE):

CREATE QUERY
DATABASE:
SYNTAX:
(create database db1;)
TABLE:
SYNTAX:
(CREATE TABLE table_name (column_name column_type...));

ALTER:
SYNTAX:
(ALTER TABLE table_name, ADD
new_column_namecolumn_definitions);
Result:

DROP:
SYNTAX:
(DROP TABLE table_name);

DROP COLUMN:
DML (DATA MANIPULATION LANGUAGE):
INSERT:
SYNTAX:
(INSERT INTO table_name VALUES (value1, value2,... valueN ); )
TABLE EMP

TABLE EMP_DEPT
UPDATE:
SYNTAX:
{(UP DATE table_name SET field1=new-value1, field2=new-
value2, ...
[W HERE Clause]}

Result:
DELETE:
SYNTAX:
: {(UP DATE table_name SET field1=new-value1, field2=new-
value2, ...
[W HERE Clause]}
DQL (DATA QUERY LANGUAGE):
SELECT:
SYNTAX:
(SELECT * FROM tables [W HERE conditions]; )
DIFFERENCE BETWEEN DESCRIBE AND SELECT

DESCRIBE:

SQL DESC statement use for describe the list of column


definitions for specified table. And it is use for describe a whole
specified table’s format.
DESCRIBE statement to get following information:

§ Column Name
§ Column allow NULL or NOT NULL
§ Datatype of the Column
§ With database size precision and If NUMERIC datatype scale.
SYNTAX:
(DESC table name;)

SELECT:

SQL SELECT statement is used to viewing data from the table.


This statement return the list of table format table data. Select
return the data list from table with format. We use asterisk (*)
sign to fetch all table columns instead of write all column name.

SYNTAX:
(SELECT * FROM table name;)
DIFFERENCE BETWEEN ALTER AND UPDATE

SQL ALTER TABLE Statement to rename table name, add new


column, modify existing column (data type, size, etc.), drop the
table column. SQL ALTER TABLE statement is a powerful
statement to add, manage or update table structure.

SYNTAX:

(ALTER TABLE table name, ADD new column name column


definition;)
ALTER: TO ADD NEW COLUMN IN EXISTING EMP TABLE
ALTER: TO RENAME THE EXISTING TABLE

ALTER: TO DROP ONE OF THE COLUMN OF THE TABLE

ALTER: TO MODIFY THE SIZE OF THE DATA

ALTER: TO ADD THE NEW COLUMN


UPDATE:
SQL UPDATE statement to only update table records with in
database. You can update all table row or update data only
matching conditionally WHERE clause.
SYNTAX:
{(UP DATE table name
SET field1=new-value1, field2=new-value2, ... [W HERE
Clause]}
UPDATE: TO UPDATE THE NAME

DIFFERENCE BETWEEN DROP AND DELETE

SQL DROP DATABASE, TABLE statement to drop the existing


database. SYNTAX: DROP TABLE table name
DROP TABLE:

DROP DATABASE:
DELETE:
SYNTAX:(DELETE FROM table name, where column name =
value;)
MySQL DELETE statement is used to delete data from the
MySQL table within the database. By using delete statement, we
can delete records on the basis of conditions.

AGGREGATE FUNCTIONS
In database management an aggregate function is a function
where the values of multiple rows are grouped together as input
on certain criteria to form a single value of more significant
meaning.
Various Aggregate Functions:
1) Count( )
2) Sum( )
3) Avg( )
4) Min( )
5) Max( )
6) First( )
7) Last( )
COUNT:
SYNTAX: (SELECT COUNT (column name) from table name;)
Returns total number of records.

SUM:
SYNTAX: (SELECT SUM (column name) AS ‘expression’ from
table name;) Sum all Not Null values of Column salary.
AVG:
SYNTAX:
(SELECT AVG (column name) AS ‘expression’ from table name;)
Function is an aggregate function that returns the average
value of a group.

MIN:
SYNTAX: (SELECT MIN(column name) from table name;)
Function returns the smallest value of the selected column

MAX:
SYNTAX:
(SELECT MAX(column name ) from table name; )
Function returns the largest value of the selected column

FIRST:
SYNTAX: SELECT column_name FROM table_name LIMIT 1;
The MySQL first function is used to return the first value of the
selected column. Here, we use limit clause to select first record
or more.
ORIGINAL EMP TABLE:

RESULT = LIMIT 1
RESULT = LIMIT 2

LAST:
SYNTAX:
(SELECT column_name FROM table_name ORDER BY
column_name DESC LIMIT 1;) MySQL last function is used to
return the last value of the selected column.
ORIGINAL EMP TABLE:

RESULT = LIMIT 1

RESULT = LIMIT 2
GROUP BY CLAUSE
The GROUP BY statement groups rows that have the same
values into summary rows. The GROUP BY clause is a SQL
command that is used to group rows that have the same values.
The GROUP BY clause is used in the SELECT statement.
Optionally it is used in conjunction with aggregate functions to
produce summary reports from the database.
SYNTAX:
{(SELECT expression1, expression2, ...expression n, Aggregate
function (expression) FROM tables [W HERE conditions] GROUP
BY expression1, expression2, ... expression n;}
ORIGINAL EMP TABLE:

RESULT:
ORIGINAL EMP_DEPT TABLE:

RESULT:
ORDER BY CLAUSE
The ORDER BY statement in sql is used to sort the fetched data
in either ascending or descending according to one or more
columns. By default ORDER BY sorts the data in ascending
order.We can use the keyword DESC to sort the data in
descending order and the keyword ASC to sort in ascending
order.
ORDER BY:
SYNTAX:
{(SELECT expressions
FROM tables [W HERE conditions]
ORDER BY expression [ ASC | DESC];}
ORIGINAL EMP TABLE:

RESULT:

ORIGINAL EMP_DEPT TABLE


RESULT:

ASCENDING ORDER:
SYNTAX:
{(SELECT expressions FROM tables [W HERE conditions] ORDER
BY expression [ ASC];}
ORIGINAL EMP TABLE:

RESULT:

ORIGINAL EMP_DEPT TABLE:


RESULT:

DESCENDING ORDER:
SYNTAX:
{(SELECT expressions FROM tables [W HERE conditions] ORDER
BY expression [ DESC];}
ORIGINAL EMP TABLE:

RESULT:

ORIGINAL EMP_DEPT TABLE:


RESULT:

WHERE CLAUSE
The SQL WHERE clause is used to specify a condition while
fetching the data from a single table or by joining with multiple
tables. If the given condition is satisfied, then only it returns a
specific value from the table. You should use the WHERE clause
to filter the records and fetching only the necessary records.
The WHERE clause is used to filter records. The WHERE clause is
used to extract only those records that fulfill a specified
condition.
SYNTAX:
(WHERE conditions;)
ORIGINAL EMP TABLE:

RESULT:
ORIGINAL EMP_DEPT TABLE

RESULT:

HAVING CLAUSE
SQL - Having Clause. The HAVING Clause enables you to specify
conditions that filter which group results appear in the results.
The WHERE clause places conditions on the selected columns,
whereas the HAVING clause places conditions on groups created
by the GROUP BY clause.
SYNTAX:
{SELECT expression1, expression2, ... expression n, Aggregate
Function (expression) FROM tables GROUP BY expression1,
expression2, ... expression n HAVING condition;}
DIFFERENCE BETWEEN HAVING AND WHERE CLAUSE
“The difference between the having and where clause in SQL is
that the where clause cannot be used with aggregates, but the
having clause can.”
1) WHERE clause is processed right after FROM clause in the
logical order of query processing, which means it is processed
before GROUP BY clause while HAVING clause is executed after
groups are created.
2) If used in GROUP BY, You can refer any column from a table
in WHERE clause but you can only use columns which are not
grouped or aggregated.
3) If you use HAVING clause without group by, it can also refer
any column but the index will not be used as opposed to WHERE
clause. For example, the following have the same result set,
however "where" will use the id index and having will do a table
scan s e l e ct * f r om t a bl e wher e i d = 1 s e l e ct * f r om t a
bl e ha vi ng i d = 1
4) You can use an aggregate function to filter rows with HAVING
clause. Because HAVING clause is processed after the rows have
been grouped, you can refer to an aggregate function in the
logical expression. For example, the following query will display
only courses which have more than 10 students : S E LE CT C o
ur s e , C OUNT( C ou rs e) a s NumOf S t uden t f r om T r ai ni n
g GROUP BY C o ur s e HAVI NG C OUNT( C OURS E) > 10
5) Another key difference between WHERE and HAVING clause
is that WHERE will use Index and HAVING will not, for example
following two queries will produce an identical result but WHERE
will use Index and HAVING will do a table scan

S E LE CT * F ROM C o ur s e WHERE I d = 1 0 1;
S E LE CT * F ROM C o ur s e HAVI NG I d = 102;

PRIMARY KEY
SQL PRIMARY KEY Constraint apply on column(s) for a uniquely
identifies each record (row) in the table.
SQL Primary Key constraint has been specified for certain
column. we can not enter duplicate data in this column.
SQL Primary Key in a table have following three special
attributes,
§ The NOT NULL attribute is automatic active.
§ The data across the column must be unique.
§ Defines column as a mandatory column.

FOREIGN KEY
SQL FOREIGN KEY Constraint apply on column(s) for whose
value must have reference in another table column (that
existing column must be primary key or unique key
constraint).SQL FOREIGN KEY constraints also known as
relationship (referential) constraints.
SYNTAX:
FOREIGN KEY (table2. column name) REF ERENC ES table1
(column name)
TABLES:

CAN’T ADD ANY DATA IN CHILD TABLE, IT SHOW ERROR AFTER


TRYING TO ADD SOMETHING. HOWEVER USER CAN ADD ANY
DATA IN PARENT TABLE WHENEVER USER WANTS. THEN USER
CAN CHANGE THE VALUES FROM CHILD TABLE.
RESULT:

NOT NULL
SQL NOT NULL Constraint enforces to a column is always
contain a value. This means that you can not insert NULL (blank)
value in this field. SQL NOT NULL Constraint applied only at
column level . You should manually define NOT NULL constraint
because table column set NULL value already.
SYNTAX: (column name data type data size NOT NULL,)
(Create table table name (column name data size Not Null)

LOGICAL OPERATOR
LIKE
SQL LIKE operator is used with WHERE clause to matches
specific pattern in a column. SQL LIKE condition apply on table
column data.
Following two wildcards are often used with the LIKE operator
§ % - Represents zero, or any number of characters
§ _ - Represents a single character
SYNTAX:
(SELECT * FROM table name W HERE column name LIKE 'value';
ORIGINAL EMP TABLE:

RESULT:
BETWEEN
SQL BETWEEN operator used for fetching within range data.
SQL BETWEEN query simply a shorthand way of expressing an
inclusive range comparison.
SYNTAX:
(SELECT * FROM table name W HERE column name BETWEEN
value AND value;)
ORIGINAL EMP TABLE:

RESULT:
AND
SQL AND condition use to test more then one conditions in
INSERT, UPDATE, DELETE, SELECT statement. AND operator
work is test first condition if true come to a second and so forth,
otherwise not check next condition.
SYNTAX:
(SELECT * FROM table name W HERE Column name conditon
'value' AND Column name condition ‘value’;)
ORIGINAL EMP TABLE:

RESULT:

OR
SQL OR Condition use to test more then one conditions in
INSERT, UPDATE, DELETE, SELECT statement. OR operator test
all condition even if condition TRUE or FALSE. And return data
when any one of the condition TRUE. SQL OR Operator same as
AND operator, return the record base filtered data. INSERT,
UPDATE, DELETE, SELECT statement perform only one of the
specified condition TRUE.
SYNTAX:
(SELECT * FROM table name W HERE Column name conditon
'value' OR Column name condition ‘value’; )

ORIGINAL EMP TABLE:

RESULT:

IN
The MySQL IN condition is used to reduce the use of multiple OR
conditions in a SELECT, INSERT, UPDATE and DELETE statement.
SYNTAX:
SELECT * FROM table name W HERE Column name IN ('values’);
ORIGINAL EMP TABLE:

RESULT

COMPARISON OPERATOR
A comparison (or relational) operator is a mathematical symbol
which is used to compare two values.
· GREATER THAN
· LESS THAN
· GREATER THAN EQUALS TO
· LESS THAN EQUALS TO
· EQUALS TO
· NOT EQUAL TO

EQUALS TO
SYNTAX: (SELECT * FROM table name WHERE column name =
value;)
GREATER THAN
SYNTAX: (SELECT * FROM table name WHERE column name >
value;)

LESS THAN
SYNTAX: (SELECT * FROM table name WHERE column name <
value;)

GREATER THAN EQAULS TO


SYNTAX: (SELECT * FROM table name WHERE column name >=
value;)

LESS THAN EQUALS TO


SYNTAX: (SELECT * FROM table name WHERE column name <=
value;)
NOT EQUAL TO
SYNTAX: (SELECT * FROM table name WHERE column name <>
value;)

JOIN
MySQL JOINS are used with SELECT statement. It is used to
retrieve data from multiple tables. It is performed whenever you
need to fetch records from two or more tables.
There are three types of MySQL joins:
o MySQL INNER JOIN (or sometimes called simple join)
o MySQL LEFT OUTER JOIN (or sometimes called LEFT JOIN)
o MySQL RIGHT OUTER JOIN (or sometimes called RIGHT JOIN)
INNER JOIN:
SYNTAX:
(SELECT table1.column name, table1.column name,
table2.column name FROM table1 INNER JOIN table2
ON table1.column name = table2.column name;)
RESULT:

LEFT OUTER JOIN:


SYNTAX:
(SELECT table1.column name, table1.column name,
table2.column name FROM table1 LEFT JOIN table2
ON table1.column name = table2.column name;)
RESULT:

RIGHT OUTER JOIN:


SYNTAX:
(SELECT table1.column name, table1.column name,
table2.column name FROM table1 RIGHT JOIN table2
ON table1.column name = table2.column name; )

RESULT:

You might also like