SlideShare a Scribd company logo
1 of 33
Introduction to MySQL
Presented by:
Amit Kumar Gupta
Flowchart-of-topic
 Database and Database Management System
 Introduction to MySQL
 Connecting and Disconnecting
 Entering Basic Queries
 Creating and Using a Database
Database and Database Management System
Student_id Student_name Branch Year
101 Rms yadav CS 3
102 Shubham Kumar CS 3
103 Sujeet Kumar CS 3
104 Rakesh Kumar ME 3
Database Management System (DBMS) is software to maintain and utilize
the collections of data (Oracle, DB2, MySQL)
MySQL Introduction
 MySQL is a database management system
 SQL stands for the Structured Query Language. It defines
how to insert, retrieve, modify and delete data
 Free from www.mysql.com
 Why are we using MySQL?
 Free (much cheaper than Oracle!)
 Each student can install MySQL locally.
 Easy to use Shell for creating tables, querying tables, etc.
 Easy to use with Java JDBC
Basic MySQL Operations
 Insert records
 Create table
 Load data
 Retrieve records
 Update records
 Delete records
 Modify table
 Join table
 Drop table
 Optimize table
 Count, Like, Order by, Group by
 More advanced ones (sub-queries, stored procedures, triggers, views …)
How MySQL stores data (by default)
 A MySQL server can store several databases
 Databases are stored as directories
 Default is at /usr/local/mysql /var/
 Tables are stored as files inside each database (directory)
 For each table, it has three files:
 table.FRM file containing information about the table structure
 table.MYD file containing the row data
 table.MYI containing any indexes belonging with this table, as well as some
statistics about the table.
Login
Enter password: *****
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 241 to server version: 3.23.49
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql>
 To exit the MySQL Shell, just type QUIT or EXIT:
mysql> QUIT
mysql> exit
Basic Queries
 Once logged in, you can try some simple queries.
 For example:
mysql> SELECT VERSION(), CURRENT_DATE;
+-----------+--------------+
| VERSION() | CURRENT_DATE |
+-----------+--------------+
| 3.23.49 | 2002-05-26 |
+-----------+--------------+
1 row in set (0.00 sec)
 Note that most MySQL commands end with a semicolon (;)
 MySQL returns the total number of rows found, and the total time to execute the
query.
Create Database
What are the current databases at the server?
mysql> show databases;
+--------------+
| Database |
+--------------+
| mysql | mysql is a database (stores users’ password …) used by system.
| test |
+--------------+
Create a database (make a directory) whose name is MyDB
mysql> create database MyDB;
Select database to use
mysql> use MyDB;
Database changed
What tables are currently stored in the MyDB database?
mysql> show tables;
Empty set (0.00 sec)
Create Table
 CREATE TABLE Table_Name (column_specifications)
 Example
mysql> CREATE TABLE student
-> (
-> Student_id INT UNSIGNED NOT NULL,
-> Student_name VARCHAR(20) NOT NULL,
-> Branch VARCHAR(5),
-> Year VARCHAR(5)
-> );
Query OK, 0 rows affected (0.00 sec)
Student_id Student_name Branch Year
Display Table Structure
mysql> show tables;
+--------------------+
| Tables_in_MyDB |
+--------------------+
| student |
+--------------------+
1 row in set (0.00 sec)
mysql> describe student;
+---------------+----------------------+------+------+----------+--------+
| Field | Type | Null | Key | Default | Extra |
+---------------+----------------------+-------+-----+-----------+-------+
| Student_id | int(10) unsigned | | | 0 | |
| Student_name | varchar(20) | | | | |
| Branch | varchar(50) | YES | | NULL | |
| Year | varchar(5) | YES | | NULL | |
+---------------+----------------------+-------+------+----------+-------+
4 rows in set (0.00 sec)
this command use for show table in current database
this this comand use for display table structure in current
database
Insert Record
 INSERT Syntax:-
 INSERT INTO table_name values(column1,column2,column3,…..);
 Example
mysql> INSERT INTO student values( 101, ‘Rms Yadav', ‘CS', ‘3’);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO student values( 102, ‘Shubham Kumar', ‘CS’,
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO student values( 103, ‘Santosh Kumar', ‘CS', ‘3’);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO student values( 104, ‘Rakesh Kumar’, ‘ME', ‘3’);
Query OK, 1 row affected (0.00 sec)
SELECT Statement
 The SELECT statement is used to select data from a database.
 The data returned is stored in a result table, called the result-set.
 SELECT Syntax
SELECT column1, column2, ...
FROM table_name;
 Here, column1, column2, ... are the field names of the table you want to
select data from. If you want to select all the fields available in the table,
 use the following syntax:
 SELECT * FROM table_name;
+---------------+--------------------- +-------+------+----------+--+
| Student_id| Student_name | Branch | Year |
+---------------+----------------------+-------+------+----------+--+
| 101 | Rms Yadav | CS | 3 |
| 102 | Shubham Kumar | CS | 3 |
| 103 | Santosh Kumar | CS | 3 |
| 104 | Rakesh Kumar | ME | 3 |
+---------------+----------------------+-------+------+-----------+---+
Selecting Particular Rows
 You can select only particular rows from your table.
 For example, if you want to verify the change that you made to Bowser's birth date,
select Bowser's record like this:
 For example:-
mysql> SELECT * FROM Student WHERE name = “Rms Yadav";
+---------------+--------------------- +-------+------+----------+--+
| Student_id| Student_name | Branch | Year |
+---------------+----------------------+-------+------+----------+--+
| 101 | Rms Yadav | CS | 3 |
+---------------+----------------------+-------+------+----------+--+
Selecting Particular Rows using Relational operator
 To find all Student record in third Year
SELECT * FROM student WHERE Year >= “3";
+---------------+--------------------- +-------+------+----------+--+
| Student_id| Student_name | Branch | Year |
+---------------+----------------------+-------+------+----------+--+
| 101 | Rms Yadav | CS | 3 |
| 102 | Shubham Kumar | CS | 3 |
| 103 | Santosh Kumar | CS | 3 |
| 104 | Rakesh Kumar | ME | 3 |
+---------------+----------------------+-------+------+-----------+---+
 To find all Student Record, use a logical AND
SELECT * FROM student WHERE Year = ‘3’ AND Branch= “CS";
 To find all Student Record, use a logical OR
SELECT * FROM student WHERE Year = “3" OR Branch=“ME”;
Selecting Particular Columns
 If you don’t want to see entire rows from your table, just name the columns in which you are
interested, separated by commas.
 For example, if you want to know when your pets were born, select the name and birth columns.
 for example:-
mysql> select Student_id, Student_name from student;
D
+---------------+--------------------- +-------+-
| Student_id | Student_name |
+---------------+----------------------+-------+
| 101 | Rms Yadav |
| 102 | Shubham Kumar |
| 103 | Santosh Kumar |
| 104 | Rakesh Kumar |
+---------------+----------------------+-------+--
Group By
 Cluster query results based on different groups
Example:-
mysql> select Branch, count(*) from student GROUP BY Branch;
+---------+----------+
| Branch | count(*)|
+---------+-----------+
| CS | 3 |
| ME | 1 |
+---------+-----------+
Different type of Key
• Super Key
• Candidate Key
• Primary Key
• Alternate key
• Composite/Compound Key
• Unique Key
• Foreign Key
Super Key and Primary Key
 1. Super Key
 Super key can be defined as a set of one or more than one keys that can be used to identify a
record/data uniquely in a table. This key includes only those fields which includes unique value as if we
take an example of Employee than Employee_Id will be the field which includes unique value and it
become easy to identify the employee from Employee_Id field.
 For Example : -Keys which can be the subset of Super Key are Primary key, Unique key and Alternate
key. As right now we don’t know about these keys so further we will discuss these keys.
 2. Primary Key
 Primary key can be defined as a set of one or more fields/columns of a table that uniquely identify a
record in database table. Record can be uniquely identify when the column which includes unique value
like Employee_Id of employee from an organization. It will not accept null values and duplicate values.
Only one primary key can be exist in a single table not more than one.
 For Example:- Suppose a table consist of Employee data with fields Employee_Name,
Employee_Address,Employee_Id and Employee_Designation so in this table only one field is there which
is used to uniquely identify detail of Employee that is Employee_Id.
Unique Key and Alternate Key
 3. Unique Key
 Unique key can be defined as a set of one or more fields/columns of a table that have the capability to
uniquely identify a record in database table. We can have other fields also in a table beyond primary key
which are also able to uniquely identify the record. It can accept only one null value and it can not have
duplicate values in it.
 For Example:-Suppose a table consist of Employee data with fields Employee_Name,
Employee_Address,Employee_Id , Employee_Designation and Employee_PhoneNo so in this table except
Employee_Id we also have an another field named Employee_PhoneNo which is can also be used to
uniquely identify the record and can termed as Unique Key.
 4. Alternate key
 Alternate key can be defined as a key that can be work as a primary key if required. We can also
understand this key as a candidate for primary key as candidate key but right now it is not a primary key.
 For Example:- Suppose a table consist of Employee data with fields Employee_Name,
Employee_Address,Employee_Id , Employee_Designation and Employee_PhoneNo in this case
Employee_PhoneNo can be the alternate key as it is also suitable to identify the record uniquely but right
now it is not primary key.
table like primary key or we can also say that other fields than primary key which can become primary key and a
table can have more than one candidate key. Each candidate key can work as primary key if required in any
case.
 For Example:- Suppose a table consist of Employee data with fields Employee_Name,
Employee_Address,Employee_Id , Employee_Designation.Employee_PANNo and Employee_PhoneNo in this table
Employee_PhoneNo and Employee_PANNo are Candidate Keys as these two fields can also work as candidate key.
 6. Composite/Compound Key
 Composite Key can be defined as a combination of more than one fields/columns of a table to uniquely identify
the record. Fields which can be combine to make composite key can be candidate, primary key.
 For Example:-Suppose a table consist of Employee data with fields Employee_Name,
Employee_Address,Employee_Id , Employee_Designation, Employee_PANNo and Employee_PhoneNo in this table
to build a composite key we combine Employee_Id and Employee_PhoneNo to fetch data from table.
 7. Foreign Key
 Foreign Key can be defined as a field/column in the Company table that is Primary key in Employee table. It can
also accept multiple null values and duplicate values. This can be easily understand with the help of example
given below.
 For Example:- We can have a Employee_Id column in the Company table which is pointing to Employee_Id
column in a Employee table where it a primary key. So with the help of foreign key we can easily identify the
data from tables.
Modify Table Structure
 ALTER TABLE table_name Operations
mysql> alter table student add primary key (Student_id);
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> describe student;
+---------------+--------------------- +-------+------+----------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+----------------------+-------+------+----------+-------+
| Student_id | int(10) unsigned | | PRI | 0 | |
| Student_name | varchar(20) | | | | |
| Branch | varchar(7) | YES | | NULL | |
| Year | varchar(5) | YES | | NULL | |
+---------------+----------------------+-------+------+-----------+-------+
4 rows in set (0.00 sec)
Update Record
 UPDATE table_name
SET which columns to change
WHERE condition
 Example
mysql> UPDATE student SET Year=‘4' WHERE Student_name='Shannon';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> SELECT * FROM student WHERE Student_name=‘Shannon’;
+------------+---------------+--------+--------+--------+
| Student_name | student_ID | Branch |Year |
+------------+---------------+--------+--------+--------+
| Rms Yadav | 101 | CS | 4 |
+------------+---------------+--------+--------+--------+
1 row in set (0.00 sec)
Delete Record
 DELETE FROM table_name WHERE condition
 Example
mysql> DELETE FROM student WHERE Student_name=‘Rms Yadav';
Query OK, 1 row affected (0.00 sec)
Mysql> DELETE FROM student;
Will delete ALL student records
Drop Table
 DROP TABLE table_name
 Example
mysql> drop table student;
Query OK, 0 rows affected (0.00 sec)
 Logout MySQL
mysq> quit;
SQL JOIN
OrderID CustomerID OrderDate
10308 2 1996-09-18
10309 37 1996-09-19
10310 77 1996-09-20
A JOIN clause is used to combine rows from two or more tables, based on a related column
between them.
Let's look at a selection from the "Orders" table:
Customer
ID
CustomerName ContactName Country
1 Alfreds Futterkiste Maria Anders Germany
2 Ana Trujillo
Emparedados y
helados
Ana Trujillo Mexico
3 Antonio Moreno
Taquería
Antonio Moreno Mexico
Customer
ID
CustomerName ContactName Country
1 Alfreds Futterkiste Maria Anders Germany
2 Ana Trujillo
Emparedados y
helados
Ana Trujillo Mexico
3 Antonio Moreno
Taquería
Antonio Moreno Mexico
Then, look at a selection from the "Customers" table:
OrderID CustomerName OrderDat
e
10308 Ana Trujillo Emparedados y helados 9/18/199
6
10365 Antonio Moreno Taquería 11/27/19
96
10383 Around the Horn 12/16/19
96
10355 Around the Horn 11/15/19
96
10278 Berglunds snabbköp 8/12/199
6
Notice that the "CustomerID" column in the "Orders" table refers to the "CustomerID" in the
"Customers" table. The relationship between the two tables above is the "CustomerID" column.
Then, we can create the following SQL statement (that contains an INNER JOIN), that selects
records that have matching values in both tables:
Example
SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
FROM Orders
INNER JOIN Customers ON Orders.CustomerID= Customers.CustomerID;
Different Types of SQL JOINs
 Different Types of SQL JOINs
 Here are the different types of the JOINs in SQL:
1.(INNER) JOIN: Returns records that have matching values in both tables
SQL LEFT JOIN Keyword
 The LEFT JOIN keyword returns all records from the left table (table1), and the matched
records from the right table (table2). The result is NULL from the right side, if there is no
match.
 LEFT JOIN Syntax
 SELECT column_name(s)
FROM table1
LEFT JOIN table2 ON table1.column_name = table2.column_name;
SQL RIGHT JOIN Keyword
 The RIGHT JOIN keyword returns all records from the right table
(table2), and the matched records from the left table (table1). The
result is NULL from the left side, when there is no match.
 RIGHT JOIN Syntax
 SELECT column_name(s)
FROM table1
RIGHT JOIN table2 ON table1.column_name = table2.column_name;
SQL FULL OUTER JOIN Keyword
 SQL FULL OUTER JOIN Keyword
 The FULL OUTER JOIN keyword return all records when there is a
match in either left (table1) or right (table2) table records.
 Note: FULL OUTER JOIN can potentially return very large result-sets!
Thank You
By Ramashankar Kumar

More Related Content

What's hot

MySQL partitions tutorial
MySQL partitions tutorialMySQL partitions tutorial
MySQL partitions tutorialGiuseppe Maxia
 
New features in Performance Schema 5.7 in action
New features in Performance Schema 5.7 in actionNew features in Performance Schema 5.7 in action
New features in Performance Schema 5.7 in actionSveta Smirnova
 
My SQL Idiosyncrasies That Bite OTN
My SQL Idiosyncrasies That Bite OTNMy SQL Idiosyncrasies That Bite OTN
My SQL Idiosyncrasies That Bite OTNRonald Bradford
 
12c Database TEMPORAL VALIDITY & FLASHBACK ARCHIVE Testing
12c Database TEMPORAL VALIDITY & FLASHBACK ARCHIVE Testing12c Database TEMPORAL VALIDITY & FLASHBACK ARCHIVE Testing
12c Database TEMPORAL VALIDITY & FLASHBACK ARCHIVE TestingMonowar Mukul
 
Lecture3 mysql gui by okello erick
Lecture3 mysql gui by okello erickLecture3 mysql gui by okello erick
Lecture3 mysql gui by okello erickokelloerick
 
MySQL for business developer - Titouan BENOIT
MySQL for business developer - Titouan BENOITMySQL for business developer - Titouan BENOIT
MySQL for business developer - Titouan BENOITTitouan BENOIT
 
Performance Schema for MySQL Troubleshooting
 Performance Schema for MySQL Troubleshooting Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingSveta Smirnova
 
Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingPerformance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingSveta Smirnova
 
Cat database
Cat databaseCat database
Cat databasetubbeles
 
MySQL Query tuning 101
MySQL Query tuning 101MySQL Query tuning 101
MySQL Query tuning 101Sveta Smirnova
 
Why Use EXPLAIN FORMAT=JSON?
 Why Use EXPLAIN FORMAT=JSON?  Why Use EXPLAIN FORMAT=JSON?
Why Use EXPLAIN FORMAT=JSON? Sveta Smirnova
 
My sql with querys
My sql with querysMy sql with querys
My sql with querysNIRMAL FELIX
 
DB2 Basic Commands - UDB
DB2 Basic Commands - UDBDB2 Basic Commands - UDB
DB2 Basic Commands - UDBSrinimf-Slides
 
Scripts related to temp tablespace
Scripts related to temp tablespaceScripts related to temp tablespace
Scripts related to temp tablespaceSoumya Das
 
Empowering Users with Analytical MDX
Empowering Users with Analytical MDXEmpowering Users with Analytical MDX
Empowering Users with Analytical MDXAlithya
 

What's hot (20)

MySQL partitions tutorial
MySQL partitions tutorialMySQL partitions tutorial
MySQL partitions tutorial
 
New features in Performance Schema 5.7 in action
New features in Performance Schema 5.7 in actionNew features in Performance Schema 5.7 in action
New features in Performance Schema 5.7 in action
 
My SQL Idiosyncrasies That Bite OTN
My SQL Idiosyncrasies That Bite OTNMy SQL Idiosyncrasies That Bite OTN
My SQL Idiosyncrasies That Bite OTN
 
Mysql basics1
Mysql basics1Mysql basics1
Mysql basics1
 
12c Database TEMPORAL VALIDITY & FLASHBACK ARCHIVE Testing
12c Database TEMPORAL VALIDITY & FLASHBACK ARCHIVE Testing12c Database TEMPORAL VALIDITY & FLASHBACK ARCHIVE Testing
12c Database TEMPORAL VALIDITY & FLASHBACK ARCHIVE Testing
 
Lecture3 mysql gui by okello erick
Lecture3 mysql gui by okello erickLecture3 mysql gui by okello erick
Lecture3 mysql gui by okello erick
 
MySQL for business developer - Titouan BENOIT
MySQL for business developer - Titouan BENOITMySQL for business developer - Titouan BENOIT
MySQL for business developer - Titouan BENOIT
 
MySQL constraints
MySQL constraintsMySQL constraints
MySQL constraints
 
Performance Schema for MySQL Troubleshooting
 Performance Schema for MySQL Troubleshooting Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL Troubleshooting
 
Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingPerformance Schema for MySQL Troubleshooting
Performance Schema for MySQL Troubleshooting
 
w_dzon05
w_dzon05w_dzon05
w_dzon05
 
Intro to my sql
Intro to my sqlIntro to my sql
Intro to my sql
 
Cat database
Cat databaseCat database
Cat database
 
Pro PostgreSQL
Pro PostgreSQLPro PostgreSQL
Pro PostgreSQL
 
MySQL Query tuning 101
MySQL Query tuning 101MySQL Query tuning 101
MySQL Query tuning 101
 
Why Use EXPLAIN FORMAT=JSON?
 Why Use EXPLAIN FORMAT=JSON?  Why Use EXPLAIN FORMAT=JSON?
Why Use EXPLAIN FORMAT=JSON?
 
My sql with querys
My sql with querysMy sql with querys
My sql with querys
 
DB2 Basic Commands - UDB
DB2 Basic Commands - UDBDB2 Basic Commands - UDB
DB2 Basic Commands - UDB
 
Scripts related to temp tablespace
Scripts related to temp tablespaceScripts related to temp tablespace
Scripts related to temp tablespace
 
Empowering Users with Analytical MDX
Empowering Users with Analytical MDXEmpowering Users with Analytical MDX
Empowering Users with Analytical MDX
 

Similar to DATA BASE || INTRODUCTION OF DATABASE \\ SQL 2018

MySQL Database System Hiep Dinh
MySQL Database System Hiep DinhMySQL Database System Hiep Dinh
MySQL Database System Hiep Dinhwebhostingguy
 
4. Data Manipulation.ppt
4. Data Manipulation.ppt4. Data Manipulation.ppt
4. Data Manipulation.pptKISHOYIANKISH
 
Bt0075, rdbms and my sql
Bt0075, rdbms and my sqlBt0075, rdbms and my sql
Bt0075, rdbms and my sqlsmumbahelp
 
Bt0075, rdbms and my sql
Bt0075, rdbms and my sqlBt0075, rdbms and my sql
Bt0075, rdbms and my sqlsmumbahelp
 
Distributed databases systems-3-2015.ppt
Distributed databases systems-3-2015.pptDistributed databases systems-3-2015.ppt
Distributed databases systems-3-2015.pptNaglaaAbdelhady
 
Introduction To Lamp P2
Introduction To Lamp P2Introduction To Lamp P2
Introduction To Lamp P2Amzad Hossain
 
Mysqlfunctions
MysqlfunctionsMysqlfunctions
MysqlfunctionsN13M
 
Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingPerformance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingSveta Smirnova
 
MySQL Kitchen : spice up your everyday SQL queries
MySQL Kitchen : spice up your everyday SQL queriesMySQL Kitchen : spice up your everyday SQL queries
MySQL Kitchen : spice up your everyday SQL queriesDamien Seguy
 
mySQL and Relational Databases
mySQL and Relational DatabasesmySQL and Relational Databases
mySQL and Relational Databaseswebhostingguy
 
Introduction databases and MYSQL
Introduction databases and MYSQLIntroduction databases and MYSQL
Introduction databases and MYSQLNaeem Junejo
 
PHP mysql Introduction database
 PHP mysql  Introduction database PHP mysql  Introduction database
PHP mysql Introduction databaseMudasir Syed
 
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)Valeriy Kravchuk
 
Optimizing queries MySQL
Optimizing queries MySQLOptimizing queries MySQL
Optimizing queries MySQLGeorgi Sotirov
 
SQL Tutorial for BCA-2
SQL Tutorial for BCA-2SQL Tutorial for BCA-2
SQL Tutorial for BCA-2Raj vardhan
 
Short Intro to PHP and MySQL
Short Intro to PHP and MySQLShort Intro to PHP and MySQL
Short Intro to PHP and MySQLJussi Pohjolainen
 

Similar to DATA BASE || INTRODUCTION OF DATABASE \\ SQL 2018 (20)

MySQL Database System Hiep Dinh
MySQL Database System Hiep DinhMySQL Database System Hiep Dinh
MySQL Database System Hiep Dinh
 
My sql1
My sql1My sql1
My sql1
 
My sql1
My sql1My sql1
My sql1
 
4. Data Manipulation.ppt
4. Data Manipulation.ppt4. Data Manipulation.ppt
4. Data Manipulation.ppt
 
MySql slides (ppt)
MySql slides (ppt)MySql slides (ppt)
MySql slides (ppt)
 
Bt0075, rdbms and my sql
Bt0075, rdbms and my sqlBt0075, rdbms and my sql
Bt0075, rdbms and my sql
 
Bt0075, rdbms and my sql
Bt0075, rdbms and my sqlBt0075, rdbms and my sql
Bt0075, rdbms and my sql
 
Distributed databases systems-3-2015.ppt
Distributed databases systems-3-2015.pptDistributed databases systems-3-2015.ppt
Distributed databases systems-3-2015.ppt
 
Introduction To Lamp P2
Introduction To Lamp P2Introduction To Lamp P2
Introduction To Lamp P2
 
Mysqlfunctions
MysqlfunctionsMysqlfunctions
Mysqlfunctions
 
Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingPerformance Schema for MySQL Troubleshooting
Performance Schema for MySQL Troubleshooting
 
MySQL Kitchen : spice up your everyday SQL queries
MySQL Kitchen : spice up your everyday SQL queriesMySQL Kitchen : spice up your everyday SQL queries
MySQL Kitchen : spice up your everyday SQL queries
 
mySQL and Relational Databases
mySQL and Relational DatabasesmySQL and Relational Databases
mySQL and Relational Databases
 
Introduction databases and MYSQL
Introduction databases and MYSQLIntroduction databases and MYSQL
Introduction databases and MYSQL
 
PHP mysql Introduction database
 PHP mysql  Introduction database PHP mysql  Introduction database
PHP mysql Introduction database
 
Mysql
MysqlMysql
Mysql
 
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
 
Optimizing queries MySQL
Optimizing queries MySQLOptimizing queries MySQL
Optimizing queries MySQL
 
SQL Tutorial for BCA-2
SQL Tutorial for BCA-2SQL Tutorial for BCA-2
SQL Tutorial for BCA-2
 
Short Intro to PHP and MySQL
Short Intro to PHP and MySQLShort Intro to PHP and MySQL
Short Intro to PHP and MySQL
 

Recently uploaded

Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 

Recently uploaded (20)

Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 

DATA BASE || INTRODUCTION OF DATABASE \\ SQL 2018

  • 1. Introduction to MySQL Presented by: Amit Kumar Gupta
  • 2. Flowchart-of-topic  Database and Database Management System  Introduction to MySQL  Connecting and Disconnecting  Entering Basic Queries  Creating and Using a Database
  • 3. Database and Database Management System Student_id Student_name Branch Year 101 Rms yadav CS 3 102 Shubham Kumar CS 3 103 Sujeet Kumar CS 3 104 Rakesh Kumar ME 3 Database Management System (DBMS) is software to maintain and utilize the collections of data (Oracle, DB2, MySQL)
  • 4. MySQL Introduction  MySQL is a database management system  SQL stands for the Structured Query Language. It defines how to insert, retrieve, modify and delete data  Free from www.mysql.com  Why are we using MySQL?  Free (much cheaper than Oracle!)  Each student can install MySQL locally.  Easy to use Shell for creating tables, querying tables, etc.  Easy to use with Java JDBC
  • 5. Basic MySQL Operations  Insert records  Create table  Load data  Retrieve records  Update records  Delete records  Modify table  Join table  Drop table  Optimize table  Count, Like, Order by, Group by  More advanced ones (sub-queries, stored procedures, triggers, views …)
  • 6. How MySQL stores data (by default)  A MySQL server can store several databases  Databases are stored as directories  Default is at /usr/local/mysql /var/  Tables are stored as files inside each database (directory)  For each table, it has three files:  table.FRM file containing information about the table structure  table.MYD file containing the row data  table.MYI containing any indexes belonging with this table, as well as some statistics about the table.
  • 7. Login Enter password: ***** Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 241 to server version: 3.23.49 Type 'help;' or 'h' for help. Type 'c' to clear the buffer. mysql>  To exit the MySQL Shell, just type QUIT or EXIT: mysql> QUIT mysql> exit
  • 8. Basic Queries  Once logged in, you can try some simple queries.  For example: mysql> SELECT VERSION(), CURRENT_DATE; +-----------+--------------+ | VERSION() | CURRENT_DATE | +-----------+--------------+ | 3.23.49 | 2002-05-26 | +-----------+--------------+ 1 row in set (0.00 sec)  Note that most MySQL commands end with a semicolon (;)  MySQL returns the total number of rows found, and the total time to execute the query.
  • 9. Create Database What are the current databases at the server? mysql> show databases; +--------------+ | Database | +--------------+ | mysql | mysql is a database (stores users’ password …) used by system. | test | +--------------+ Create a database (make a directory) whose name is MyDB mysql> create database MyDB; Select database to use mysql> use MyDB; Database changed What tables are currently stored in the MyDB database? mysql> show tables; Empty set (0.00 sec)
  • 10. Create Table  CREATE TABLE Table_Name (column_specifications)  Example mysql> CREATE TABLE student -> ( -> Student_id INT UNSIGNED NOT NULL, -> Student_name VARCHAR(20) NOT NULL, -> Branch VARCHAR(5), -> Year VARCHAR(5) -> ); Query OK, 0 rows affected (0.00 sec) Student_id Student_name Branch Year
  • 11. Display Table Structure mysql> show tables; +--------------------+ | Tables_in_MyDB | +--------------------+ | student | +--------------------+ 1 row in set (0.00 sec) mysql> describe student; +---------------+----------------------+------+------+----------+--------+ | Field | Type | Null | Key | Default | Extra | +---------------+----------------------+-------+-----+-----------+-------+ | Student_id | int(10) unsigned | | | 0 | | | Student_name | varchar(20) | | | | | | Branch | varchar(50) | YES | | NULL | | | Year | varchar(5) | YES | | NULL | | +---------------+----------------------+-------+------+----------+-------+ 4 rows in set (0.00 sec) this command use for show table in current database this this comand use for display table structure in current database
  • 12. Insert Record  INSERT Syntax:-  INSERT INTO table_name values(column1,column2,column3,…..);  Example mysql> INSERT INTO student values( 101, ‘Rms Yadav', ‘CS', ‘3’); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO student values( 102, ‘Shubham Kumar', ‘CS’, Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO student values( 103, ‘Santosh Kumar', ‘CS', ‘3’); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO student values( 104, ‘Rakesh Kumar’, ‘ME', ‘3’); Query OK, 1 row affected (0.00 sec)
  • 13. SELECT Statement  The SELECT statement is used to select data from a database.  The data returned is stored in a result table, called the result-set.  SELECT Syntax SELECT column1, column2, ... FROM table_name;  Here, column1, column2, ... are the field names of the table you want to select data from. If you want to select all the fields available in the table,  use the following syntax:  SELECT * FROM table_name; +---------------+--------------------- +-------+------+----------+--+ | Student_id| Student_name | Branch | Year | +---------------+----------------------+-------+------+----------+--+ | 101 | Rms Yadav | CS | 3 | | 102 | Shubham Kumar | CS | 3 | | 103 | Santosh Kumar | CS | 3 | | 104 | Rakesh Kumar | ME | 3 | +---------------+----------------------+-------+------+-----------+---+
  • 14. Selecting Particular Rows  You can select only particular rows from your table.  For example, if you want to verify the change that you made to Bowser's birth date, select Bowser's record like this:  For example:- mysql> SELECT * FROM Student WHERE name = “Rms Yadav"; +---------------+--------------------- +-------+------+----------+--+ | Student_id| Student_name | Branch | Year | +---------------+----------------------+-------+------+----------+--+ | 101 | Rms Yadav | CS | 3 | +---------------+----------------------+-------+------+----------+--+
  • 15. Selecting Particular Rows using Relational operator  To find all Student record in third Year SELECT * FROM student WHERE Year >= “3"; +---------------+--------------------- +-------+------+----------+--+ | Student_id| Student_name | Branch | Year | +---------------+----------------------+-------+------+----------+--+ | 101 | Rms Yadav | CS | 3 | | 102 | Shubham Kumar | CS | 3 | | 103 | Santosh Kumar | CS | 3 | | 104 | Rakesh Kumar | ME | 3 | +---------------+----------------------+-------+------+-----------+---+  To find all Student Record, use a logical AND SELECT * FROM student WHERE Year = ‘3’ AND Branch= “CS";  To find all Student Record, use a logical OR SELECT * FROM student WHERE Year = “3" OR Branch=“ME”;
  • 16. Selecting Particular Columns  If you don’t want to see entire rows from your table, just name the columns in which you are interested, separated by commas.  For example, if you want to know when your pets were born, select the name and birth columns.  for example:- mysql> select Student_id, Student_name from student; D +---------------+--------------------- +-------+- | Student_id | Student_name | +---------------+----------------------+-------+ | 101 | Rms Yadav | | 102 | Shubham Kumar | | 103 | Santosh Kumar | | 104 | Rakesh Kumar | +---------------+----------------------+-------+--
  • 17. Group By  Cluster query results based on different groups Example:- mysql> select Branch, count(*) from student GROUP BY Branch; +---------+----------+ | Branch | count(*)| +---------+-----------+ | CS | 3 | | ME | 1 | +---------+-----------+
  • 18. Different type of Key • Super Key • Candidate Key • Primary Key • Alternate key • Composite/Compound Key • Unique Key • Foreign Key
  • 19. Super Key and Primary Key  1. Super Key  Super key can be defined as a set of one or more than one keys that can be used to identify a record/data uniquely in a table. This key includes only those fields which includes unique value as if we take an example of Employee than Employee_Id will be the field which includes unique value and it become easy to identify the employee from Employee_Id field.  For Example : -Keys which can be the subset of Super Key are Primary key, Unique key and Alternate key. As right now we don’t know about these keys so further we will discuss these keys.  2. Primary Key  Primary key can be defined as a set of one or more fields/columns of a table that uniquely identify a record in database table. Record can be uniquely identify when the column which includes unique value like Employee_Id of employee from an organization. It will not accept null values and duplicate values. Only one primary key can be exist in a single table not more than one.  For Example:- Suppose a table consist of Employee data with fields Employee_Name, Employee_Address,Employee_Id and Employee_Designation so in this table only one field is there which is used to uniquely identify detail of Employee that is Employee_Id.
  • 20. Unique Key and Alternate Key  3. Unique Key  Unique key can be defined as a set of one or more fields/columns of a table that have the capability to uniquely identify a record in database table. We can have other fields also in a table beyond primary key which are also able to uniquely identify the record. It can accept only one null value and it can not have duplicate values in it.  For Example:-Suppose a table consist of Employee data with fields Employee_Name, Employee_Address,Employee_Id , Employee_Designation and Employee_PhoneNo so in this table except Employee_Id we also have an another field named Employee_PhoneNo which is can also be used to uniquely identify the record and can termed as Unique Key.  4. Alternate key  Alternate key can be defined as a key that can be work as a primary key if required. We can also understand this key as a candidate for primary key as candidate key but right now it is not a primary key.  For Example:- Suppose a table consist of Employee data with fields Employee_Name, Employee_Address,Employee_Id , Employee_Designation and Employee_PhoneNo in this case Employee_PhoneNo can be the alternate key as it is also suitable to identify the record uniquely but right now it is not primary key.
  • 21. table like primary key or we can also say that other fields than primary key which can become primary key and a table can have more than one candidate key. Each candidate key can work as primary key if required in any case.  For Example:- Suppose a table consist of Employee data with fields Employee_Name, Employee_Address,Employee_Id , Employee_Designation.Employee_PANNo and Employee_PhoneNo in this table Employee_PhoneNo and Employee_PANNo are Candidate Keys as these two fields can also work as candidate key.  6. Composite/Compound Key  Composite Key can be defined as a combination of more than one fields/columns of a table to uniquely identify the record. Fields which can be combine to make composite key can be candidate, primary key.  For Example:-Suppose a table consist of Employee data with fields Employee_Name, Employee_Address,Employee_Id , Employee_Designation, Employee_PANNo and Employee_PhoneNo in this table to build a composite key we combine Employee_Id and Employee_PhoneNo to fetch data from table.  7. Foreign Key  Foreign Key can be defined as a field/column in the Company table that is Primary key in Employee table. It can also accept multiple null values and duplicate values. This can be easily understand with the help of example given below.  For Example:- We can have a Employee_Id column in the Company table which is pointing to Employee_Id column in a Employee table where it a primary key. So with the help of foreign key we can easily identify the data from tables.
  • 22. Modify Table Structure  ALTER TABLE table_name Operations mysql> alter table student add primary key (Student_id); Query OK, 0 rows affected (0.00 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> describe student; +---------------+--------------------- +-------+------+----------+-------+ | Field | Type | Null | Key | Default | Extra | +---------------+----------------------+-------+------+----------+-------+ | Student_id | int(10) unsigned | | PRI | 0 | | | Student_name | varchar(20) | | | | | | Branch | varchar(7) | YES | | NULL | | | Year | varchar(5) | YES | | NULL | | +---------------+----------------------+-------+------+-----------+-------+ 4 rows in set (0.00 sec)
  • 23. Update Record  UPDATE table_name SET which columns to change WHERE condition  Example mysql> UPDATE student SET Year=‘4' WHERE Student_name='Shannon'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> SELECT * FROM student WHERE Student_name=‘Shannon’; +------------+---------------+--------+--------+--------+ | Student_name | student_ID | Branch |Year | +------------+---------------+--------+--------+--------+ | Rms Yadav | 101 | CS | 4 | +------------+---------------+--------+--------+--------+ 1 row in set (0.00 sec)
  • 24. Delete Record  DELETE FROM table_name WHERE condition  Example mysql> DELETE FROM student WHERE Student_name=‘Rms Yadav'; Query OK, 1 row affected (0.00 sec) Mysql> DELETE FROM student; Will delete ALL student records
  • 25. Drop Table  DROP TABLE table_name  Example mysql> drop table student; Query OK, 0 rows affected (0.00 sec)  Logout MySQL mysq> quit;
  • 26. SQL JOIN OrderID CustomerID OrderDate 10308 2 1996-09-18 10309 37 1996-09-19 10310 77 1996-09-20 A JOIN clause is used to combine rows from two or more tables, based on a related column between them. Let's look at a selection from the "Orders" table:
  • 27. Customer ID CustomerName ContactName Country 1 Alfreds Futterkiste Maria Anders Germany 2 Ana Trujillo Emparedados y helados Ana Trujillo Mexico 3 Antonio Moreno Taquería Antonio Moreno Mexico Customer ID CustomerName ContactName Country 1 Alfreds Futterkiste Maria Anders Germany 2 Ana Trujillo Emparedados y helados Ana Trujillo Mexico 3 Antonio Moreno Taquería Antonio Moreno Mexico Then, look at a selection from the "Customers" table:
  • 28. OrderID CustomerName OrderDat e 10308 Ana Trujillo Emparedados y helados 9/18/199 6 10365 Antonio Moreno Taquería 11/27/19 96 10383 Around the Horn 12/16/19 96 10355 Around the Horn 11/15/19 96 10278 Berglunds snabbköp 8/12/199 6 Notice that the "CustomerID" column in the "Orders" table refers to the "CustomerID" in the "Customers" table. The relationship between the two tables above is the "CustomerID" column. Then, we can create the following SQL statement (that contains an INNER JOIN), that selects records that have matching values in both tables: Example SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate FROM Orders INNER JOIN Customers ON Orders.CustomerID= Customers.CustomerID;
  • 29. Different Types of SQL JOINs  Different Types of SQL JOINs  Here are the different types of the JOINs in SQL: 1.(INNER) JOIN: Returns records that have matching values in both tables
  • 30. SQL LEFT JOIN Keyword  The LEFT JOIN keyword returns all records from the left table (table1), and the matched records from the right table (table2). The result is NULL from the right side, if there is no match.  LEFT JOIN Syntax  SELECT column_name(s) FROM table1 LEFT JOIN table2 ON table1.column_name = table2.column_name;
  • 31. SQL RIGHT JOIN Keyword  The RIGHT JOIN keyword returns all records from the right table (table2), and the matched records from the left table (table1). The result is NULL from the left side, when there is no match.  RIGHT JOIN Syntax  SELECT column_name(s) FROM table1 RIGHT JOIN table2 ON table1.column_name = table2.column_name;
  • 32. SQL FULL OUTER JOIN Keyword  SQL FULL OUTER JOIN Keyword  The FULL OUTER JOIN keyword return all records when there is a match in either left (table1) or right (table2) table records.  Note: FULL OUTER JOIN can potentially return very large result-sets!