SlideShare a Scribd company logo
1 of 6
Download to read offline
Practical No: 4
Problem Statement: Design at least 10 SQL queries for suitable database
application using SQL DML statements:
all types of Join, Sub-Query and View.
--------------------------------------------------------------------------------
-------------------------------
##Sub-Query
mysql> select * from emp;
+-------+--------+-----------+------+------------+---------+---------+--------+
| empno | ename | job | mgr | hiredate | sal | comm | deptno |
+-------+--------+-----------+------+------------+---------+---------+--------+
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | NULL | 20 |
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 |
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 |
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | NULL | 20 |
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 |
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | NULL | 30 |
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | NULL | 10 |
| 7788 | SCOTT | ANALYST | 7566 | 1982-12-09 | 3000.00 | NULL | 20 |
| 7839 | KING | PRESIDENT | NULL | 1981-11-17 | 5000.00 | NULL | 10 |
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 |
| 7876 | ADAMS | CLERK | 7788 | 1983-01-12 | 1100.00 | NULL | 20 |
| 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | NULL | 30 |
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | NULL | 20 |
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | NULL | 10 |
+-------+--------+-----------+------+------------+---------+---------+--------+
14 rows in set (0.00 sec)
mysql> select ename,sal,deptno from emp where deptno= (select deptno from emp
where ename="SMITH");
+-------+---------+--------+
| ename | sal | deptno |
+-------+---------+--------+
| SMITH | 800.00 | 20 |
| JONES | 2975.00 | 20 |
| SCOTT | 3000.00 | 20 |
| ADAMS | 1100.00 | 20 |
| FORD | 3000.00 | 20 |
+-------+---------+--------+
5 rows in set (0.00 sec)
mysql> select ename,sal,deptno from emp where deptno= (select deptno from emp
where ename="SMITH") and ename<>"SMITH";
+-------+---------+--------+
| ename | sal | deptno |
+-------+---------+--------+
| JONES | 2975.00 | 20 |
| SCOTT | 3000.00 | 20 |
| ADAMS | 1100.00 | 20 |
| FORD | 3000.00 | 20 |
+-------+---------+--------+
4 rows in set (0.00 sec)
mysql> select ename,sal,deptno from emp where deptno= (select deptno from emp
where ename="SMITH");
+-------+---------+--------+
| ename | sal | deptno |
+-------+---------+--------+
| SMITH | 800.00 | 20 |
| JONES | 2975.00 | 20 |
| SCOTT | 3000.00 | 20 |
| ADAMS | 1100.00 | 20 |
| FORD | 3000.00 | 20 |
+-------+---------+--------+
5 rows in set (0.00 sec)
mysql> select ename,sal,deptno from emp where sal> (select sal from emp where
ename="SMITH");
+--------+---------+--------+
| ename | sal | deptno |
+--------+---------+--------+
| ALLEN | 1600.00 | 30 |
| WARD | 1250.00 | 30 |
| JONES | 2975.00 | 20 |
| MARTIN | 1250.00 | 30 |
| BLAKE | 2850.00 | 30 |
| CLARK | 2450.00 | 10 |
| SCOTT | 3000.00 | 20 |
| KING | 5000.00 | 10 |
| TURNER | 1500.00 | 30 |
| ADAMS | 1100.00 | 20 |
| JAMES | 950.00 | 30 |
| FORD | 3000.00 | 20 |
| MILLER | 1300.00 | 10 |
+--------+---------+--------+
13 rows in set (0.00 sec)
mysql> select ename,sal,deptno from emp where sal> (select sal from emp where
ename="SMITH") and ename<>"SMITH";
+--------+---------+--------+
| ename | sal | deptno |
+--------+---------+--------+
| ALLEN | 1600.00 | 30 |
| WARD | 1250.00 | 30 |
| JONES | 2975.00 | 20 |
| MARTIN | 1250.00 | 30 |
| BLAKE | 2850.00 | 30 |
| CLARK | 2450.00 | 10 |
| SCOTT | 3000.00 | 20 |
| KING | 5000.00 | 10 |
| TURNER | 1500.00 | 30 |
| ADAMS | 1100.00 | 20 |
| JAMES | 950.00 | 30 |
| FORD | 3000.00 | 20 |
| MILLER | 1300.00 | 10 |
+--------+---------+--------+
13 rows in set (0.00 sec)
mysql> select ename,sal,deptno from emp where sal in(select sal from emp where
ename="SMITH" OR ename="SCOTT" );
+-------+---------+--------+
| ename | sal | deptno |
+-------+---------+--------+
| SMITH | 800.00 | 20 |
| SCOTT | 3000.00 | 20 |
| FORD | 3000.00 | 20 |
+-------+---------+--------+
3 rows in set (0.00 sec)
mysql> select ename,sal,deptno from emp where sal in(select sal from emp where
ename="SMITH" OR ename="SCOTT" );
+-------+---------+--------+
| ename | sal | deptno |
+-------+---------+--------+
| SMITH | 800.00 | 20 |
| SCOTT | 3000.00 | 20 |
| FORD | 3000.00 | 20 |
+-------+---------+--------+
3 rows in set (0.00 sec)
mysql> select ename,sal,deptno from emp where deptno in(select deptno from emp
where ename="SMITH" OR ename="SCOTT" );
+-------+---------+--------+
| ename | sal | deptno |
+-------+---------+--------+
| SMITH | 800.00 | 20 |
| JONES | 2975.00 | 20 |
| SCOTT | 3000.00 | 20 |
| ADAMS | 1100.00 | 20 |
| FORD | 3000.00 | 20 |
+-------+---------+--------+
5 rows in set (0.00 sec)
mysql> select ename,sal,deptno from emp where deptno in(select deptno from emp
where ename="SMITH" OR ename="MILLER" );
+--------+---------+--------+
| ename | sal | deptno |
+--------+---------+--------+
| SMITH | 800.00 | 20 |
| JONES | 2975.00 | 20 |
| CLARK | 2450.00 | 10 |
| SCOTT | 3000.00 | 20 |
| KING | 5000.00 | 10 |
| ADAMS | 1100.00 | 20 |
| FORD | 3000.00 | 20 |
| MILLER | 1300.00 | 10 |
+--------+---------+--------+
8 rows in set (0.00 sec)
mysql> select ename,sal,deptno from emp where deptno > ALL(select deptno from
emp where ename="SMITH" OR ename="MILLER" );
+--------+---------+--------+
| ename | sal | deptno |
+--------+---------+--------+
| ALLEN | 1600.00 | 30 |
| WARD | 1250.00 | 30 |
| MARTIN | 1250.00 | 30 |
| BLAKE | 2850.00 | 30 |
| TURNER | 1500.00 | 30 |
| JAMES | 950.00 | 30 |
+--------+---------+--------+
6 rows in set (0.00 sec)
mysql> select ename,sal,deptno from emp where deptno > ANY(select deptno from
emp where ename="SMITH" OR ename="MILLER" );
+--------+---------+--------+
| ename | sal | deptno |
+--------+---------+--------+
| SMITH | 800.00 | 20 |
| ALLEN | 1600.00 | 30 |
| WARD | 1250.00 | 30 |
| JONES | 2975.00 | 20 |
| MARTIN | 1250.00 | 30 |
| BLAKE | 2850.00 | 30 |
| SCOTT | 3000.00 | 20 |
| TURNER | 1500.00 | 30 |
| ADAMS | 1100.00 | 20 |
| JAMES | 950.00 | 30 |
| FORD | 3000.00 | 20 |
+--------+---------+--------+
11 rows in set (0.00 sec)
mysql> select ename,sal,deptno from emp where deptno > ANY(select deptno from
emp where ename="TURNER" OR ename="MILLER" );
+--------+---------+--------+
| ename | sal | deptno |
+--------+---------+--------+
| SMITH | 800.00 | 20 |
| ALLEN | 1600.00 | 30 |
| WARD | 1250.00 | 30 |
| JONES | 2975.00 | 20 |
| MARTIN | 1250.00 | 30 |
| BLAKE | 2850.00 | 30 |
| SCOTT | 3000.00 | 20 |
| TURNER | 1500.00 | 30 |
| ADAMS | 1100.00 | 20 |
| JAMES | 950.00 | 30 |
| FORD | 3000.00 | 20 |
+--------+---------+--------+
11 rows in set (0.00 sec)
mysql> select ename,sal,deptno from emp where deptno > ANY(select deptno from
emp where ename="TURNER" OR ename="SCOTT" );
+--------+---------+--------+
| ename | sal | deptno |
+--------+---------+--------+
| ALLEN | 1600.00 | 30 |
| WARD | 1250.00 | 30 |
| MARTIN | 1250.00 | 30 |
| BLAKE | 2850.00 | 30 |
| TURNER | 1500.00 | 30 |
| JAMES | 950.00 | 30 |
+--------+---------+--------+
6 rows in set (0.00 sec)
mysql> select ename,sal,deptno from emp where deptno > all(select deptno from
emp where ename="TURNER" OR ename="SCOTT" );
Empty set (0.00 sec)
mysql> select ename,sal,deptno from emp where sal > ANY(select sal from emp
where ename="TURNER" OR ename="SCOTT" );
+-------+---------+--------+
| ename | sal | deptno |
+-------+---------+--------+
| ALLEN | 1600.00 | 30 |
| JONES | 2975.00 | 20 |
| BLAKE | 2850.00 | 30 |
| CLARK | 2450.00 | 10 |
| SCOTT | 3000.00 | 20 |
| KING | 5000.00 | 10 |
| FORD | 3000.00 | 20 |
+-------+---------+--------+
7 rows in set (0.00 sec)
mysql> select ename,sal,deptno from emp where sal > ALL(select sal from emp
where ename="TURNER" OR ename="SCOTT" );
+-------+---------+--------+
| ename | sal | deptno |
+-------+---------+--------+
| KING | 5000.00 | 10 |
+-------+---------+--------+
1 row in set (0.00 sec)
mysql> select ename,deptno from emp where deptno=(select deptno from dept where
dname="RESEARCH");
+-------+--------+
| ename | deptno |
+-------+--------+
| SMITH | 20 |
| JONES | 20 |
| SCOTT | 20 |
| ADAMS | 20 |
| FORD | 20 |
+-------+--------+
5 rows in set (0.00 sec)
##Jion
mysql> create table orange(o_id varchar(20),price int(12));
Query OK, 0 rows affected (0.35 sec)
mysql> create table apple(a_id varchar(20),price int(12));
Query OK, 0 rows affected (0.06 sec)
mysql> insert into orange values("O1",50),("O2",60);
Query OK, 2 rows affected (0.30 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> insert into apple values("A1",60),("A2",60);
Query OK, 2 rows affected (0.30 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> select * from apple;
+------+-------+
| a_id | price |
+------+-------+
| A1 | 60 |
| A2 | 60 |
+------+-------+
2 rows in set (0.00 sec)
mysql> select * from orange;
+------+-------+
| o_id | price |
+------+-------+
| O1 | 50 |
| O2 | 60 |
+------+-------+
2 rows in set (0.00 sec)
mysql> select * from orange,apple;
+------+-------+------+-------+
| o_id | price | a_id | price |
+------+-------+------+-------+
| O1 | 50 | A1 | 60 |
| O2 | 60 | A1 | 60 |
| O1 | 50 | A2 | 60 |
| O2 | 60 | A2 | 60 |
+------+-------+------+-------+
4 rows in set (0.00 sec)
mysql> select * from orange o inner join apple a on o.price=a.price;
+------+-------+------+-------+
| o_id | price | a_id | price |
+------+-------+------+-------+
| O2 | 60 | A1 | 60 |
| O2 | 60 | A2 | 60 |
+------+-------+------+-------+
2 rows in set (0.04 sec)
mysql> select * from orange o left outer join apple a on o.price=a.price;
+------+-------+------+-------+
| o_id | price | a_id | price |
+------+-------+------+-------+
| O2 | 60 | A1 | 60 |
| O2 | 60 | A2 | 60 |
| O1 | 50 | NULL | NULL |
+------+-------+------+-------+
3 rows in set (0.00 sec)
mysql> select * from orange o right outer join apple a on o.price=a.price;
+------+-------+------+-------+
| o_id | price | a_id | price |
+------+-------+------+-------+
| O2 | 60 | A1 | 60 |
| O2 | 60 | A2 | 60 |
+------+-------+------+-------+
2 rows in set (0.00 sec)
mysql> (select * from orange o left outer join apple a on o.price=a.price)
union(select * from orange o right outer join apple a on o.price=a.price);
+------+-------+------+-------+
| o_id | price | a_id | price |
+------+-------+------+-------+
| O2 | 60 | A1 | 60 |
| O2 | 60 | A2 | 60 |
| O1 | 50 | NULL | NULL |
+------+-------+------+-------+

More Related Content

What's hot

Lecture 16 memory bounded search
Lecture 16 memory bounded searchLecture 16 memory bounded search
Lecture 16 memory bounded searchHema Kashyap
 
Association rule mining
Association rule miningAssociation rule mining
Association rule miningAcad
 
Getweeklyhoursbyuser
GetweeklyhoursbyuserGetweeklyhoursbyuser
Getweeklyhoursbyuserhasheemm
 
SQL window functions for MySQL
SQL window functions for MySQLSQL window functions for MySQL
SQL window functions for MySQLDag H. Wanvik
 
Using Optimizer Hints to Improve MySQL Query Performance
Using Optimizer Hints to Improve MySQL Query PerformanceUsing Optimizer Hints to Improve MySQL Query Performance
Using Optimizer Hints to Improve MySQL Query Performanceoysteing
 
K means Clustering
K means ClusteringK means Clustering
K means ClusteringEdureka!
 
Virtualization in Cloud Computing and Machine reference Model
Virtualization in Cloud Computing and Machine reference ModelVirtualization in Cloud Computing and Machine reference Model
Virtualization in Cloud Computing and Machine reference ModelDr Neelesh Jain
 
distributed Computing system model
distributed Computing system modeldistributed Computing system model
distributed Computing system modelHarshad Umredkar
 
02 problem solving_search_control
02 problem solving_search_control02 problem solving_search_control
02 problem solving_search_controlPraveen Kumar
 
MySQL Performance Schema in 20 Minutes
 MySQL Performance Schema in 20 Minutes MySQL Performance Schema in 20 Minutes
MySQL Performance Schema in 20 MinutesSveta Smirnova
 
Content Delivery Networks (CDN)
Content Delivery Networks (CDN)Content Delivery Networks (CDN)
Content Delivery Networks (CDN)Dilum Bandara
 
Optimizing queries MySQL
Optimizing queries MySQLOptimizing queries MySQL
Optimizing queries MySQLGeorgi Sotirov
 
Machine Learning-Linear regression
Machine Learning-Linear regressionMachine Learning-Linear regression
Machine Learning-Linear regressionkishanthkumaar
 
FOSSASIA - MySQL Cookbook 4e Journey APR 2023.pdf
FOSSASIA - MySQL Cookbook 4e Journey APR 2023.pdfFOSSASIA - MySQL Cookbook 4e Journey APR 2023.pdf
FOSSASIA - MySQL Cookbook 4e Journey APR 2023.pdfAlkin Tezuysal
 

What's hot (20)

dbms lab manual
dbms lab manualdbms lab manual
dbms lab manual
 
Lecture 16 memory bounded search
Lecture 16 memory bounded searchLecture 16 memory bounded search
Lecture 16 memory bounded search
 
Association rule mining
Association rule miningAssociation rule mining
Association rule mining
 
Getweeklyhoursbyuser
GetweeklyhoursbyuserGetweeklyhoursbyuser
Getweeklyhoursbyuser
 
SQL window functions for MySQL
SQL window functions for MySQLSQL window functions for MySQL
SQL window functions for MySQL
 
Using Optimizer Hints to Improve MySQL Query Performance
Using Optimizer Hints to Improve MySQL Query PerformanceUsing Optimizer Hints to Improve MySQL Query Performance
Using Optimizer Hints to Improve MySQL Query Performance
 
Sql ch 13 - sql-views
Sql ch 13 - sql-viewsSql ch 13 - sql-views
Sql ch 13 - sql-views
 
K means Clustering
K means ClusteringK means Clustering
K means Clustering
 
Boston housing data analysis
Boston housing data analysisBoston housing data analysis
Boston housing data analysis
 
Virtualization in Cloud Computing and Machine reference Model
Virtualization in Cloud Computing and Machine reference ModelVirtualization in Cloud Computing and Machine reference Model
Virtualization in Cloud Computing and Machine reference Model
 
Google Cloud Platform
Google Cloud Platform Google Cloud Platform
Google Cloud Platform
 
distributed Computing system model
distributed Computing system modeldistributed Computing system model
distributed Computing system model
 
Hierachical clustering
Hierachical clusteringHierachical clustering
Hierachical clustering
 
02 problem solving_search_control
02 problem solving_search_control02 problem solving_search_control
02 problem solving_search_control
 
MySQL Performance Schema in 20 Minutes
 MySQL Performance Schema in 20 Minutes MySQL Performance Schema in 20 Minutes
MySQL Performance Schema in 20 Minutes
 
Content Delivery Networks (CDN)
Content Delivery Networks (CDN)Content Delivery Networks (CDN)
Content Delivery Networks (CDN)
 
Optimizing queries MySQL
Optimizing queries MySQLOptimizing queries MySQL
Optimizing queries MySQL
 
K - Nearest neighbor ( KNN )
K - Nearest neighbor  ( KNN )K - Nearest neighbor  ( KNN )
K - Nearest neighbor ( KNN )
 
Machine Learning-Linear regression
Machine Learning-Linear regressionMachine Learning-Linear regression
Machine Learning-Linear regression
 
FOSSASIA - MySQL Cookbook 4e Journey APR 2023.pdf
FOSSASIA - MySQL Cookbook 4e Journey APR 2023.pdfFOSSASIA - MySQL Cookbook 4e Journey APR 2023.pdf
FOSSASIA - MySQL Cookbook 4e Journey APR 2023.pdf
 

Similar to database application using SQL DML statements: all types of Join, Sub-Query and View.

Statements project 2
Statements project 2Statements project 2
Statements project 2AlexisHarvey8
 
Sangam 19 - Analytic SQL
Sangam 19 - Analytic SQLSangam 19 - Analytic SQL
Sangam 19 - Analytic SQLConnor McDonald
 
Cat database
Cat databaseCat database
Cat databasetubbeles
 
Analytics functions in mysql, oracle and hive
Analytics functions in mysql, oracle and hiveAnalytics functions in mysql, oracle and hive
Analytics functions in mysql, oracle and hiveAnkit Beohar
 
Mysqlfunctions
MysqlfunctionsMysqlfunctions
MysqlfunctionsN13M
 
MySQL5.7で遊んでみよう
MySQL5.7で遊んでみようMySQL5.7で遊んでみよう
MySQL5.7で遊んでみようyoku0825
 
MySQL Idiosyncrasies That Bite SF
MySQL Idiosyncrasies That Bite SFMySQL Idiosyncrasies That Bite SF
MySQL Idiosyncrasies That Bite SFRonald Bradford
 
My sql statements by okello erick
My sql statements by okello erickMy sql statements by okello erick
My sql statements by okello erickokelloerick
 
80 different SQL Queries with output
80 different SQL Queries with output80 different SQL Queries with output
80 different SQL Queries with outputNexus
 
4. Data Manipulation.ppt
4. Data Manipulation.ppt4. Data Manipulation.ppt
4. Data Manipulation.pptKISHOYIANKISH
 

Similar to database application using SQL DML statements: all types of Join, Sub-Query and View. (20)

Mysql and html
Mysql and html Mysql and html
Mysql and html
 
Empresa completo
Empresa completoEmpresa completo
Empresa completo
 
Statements project 2
Statements project 2Statements project 2
Statements project 2
 
Sangam 19 - Analytic SQL
Sangam 19 - Analytic SQLSangam 19 - Analytic SQL
Sangam 19 - Analytic SQL
 
Analytic SQL Sep 2013
Analytic SQL Sep 2013Analytic SQL Sep 2013
Analytic SQL Sep 2013
 
Cat database
Cat databaseCat database
Cat database
 
Analytics functions in mysql, oracle and hive
Analytics functions in mysql, oracle and hiveAnalytics functions in mysql, oracle and hive
Analytics functions in mysql, oracle and hive
 
Intro to my sql
Intro to my sqlIntro to my sql
Intro to my sql
 
Mysqlfunctions
MysqlfunctionsMysqlfunctions
Mysqlfunctions
 
MySQL5.7で遊んでみよう
MySQL5.7で遊んでみようMySQL5.7で遊んでみよう
MySQL5.7で遊んでみよう
 
MySQL Idiosyncrasies That Bite SF
MySQL Idiosyncrasies That Bite SFMySQL Idiosyncrasies That Bite SF
MySQL Idiosyncrasies That Bite SF
 
My sql statements by okello erick
My sql statements by okello erickMy sql statements by okello erick
My sql statements by okello erick
 
80 different SQL Queries with output
80 different SQL Queries with output80 different SQL Queries with output
80 different SQL Queries with output
 
ORACLE NOTES
ORACLE NOTESORACLE NOTES
ORACLE NOTES
 
Hanya contoh saja dari xampp
Hanya contoh saja dari xamppHanya contoh saja dari xampp
Hanya contoh saja dari xampp
 
Tugas praktikum smbd
Tugas praktikum smbdTugas praktikum smbd
Tugas praktikum smbd
 
Explain
ExplainExplain
Explain
 
KScope19 - SQL Features
KScope19 - SQL FeaturesKScope19 - SQL Features
KScope19 - SQL Features
 
Cube rollup slides
Cube rollup slidesCube rollup slides
Cube rollup slides
 
4. Data Manipulation.ppt
4. Data Manipulation.ppt4. Data Manipulation.ppt
4. Data Manipulation.ppt
 

More from bhavesh lande

The Annual G20 Scorecard – Research Performance 2019
The Annual G20 Scorecard – Research Performance 2019 The Annual G20 Scorecard – Research Performance 2019
The Annual G20 Scorecard – Research Performance 2019 bhavesh lande
 
information control and Security system
information control and Security systeminformation control and Security system
information control and Security systembhavesh lande
 
information technology and infrastructures choices
information technology and  infrastructures choicesinformation technology and  infrastructures choices
information technology and infrastructures choicesbhavesh lande
 
ethical issues,social issues
 ethical issues,social issues ethical issues,social issues
ethical issues,social issuesbhavesh lande
 
managing inforamation system
managing inforamation systemmanaging inforamation system
managing inforamation systembhavesh lande
 
• E-commerce, e-business ,e-governance
• E-commerce, e-business ,e-governance• E-commerce, e-business ,e-governance
• E-commerce, e-business ,e-governancebhavesh lande
 
organisations and information systems
organisations and  information systemsorganisations and  information systems
organisations and information systemsbhavesh lande
 
IT stratergy and digital goods
IT stratergy and digital goodsIT stratergy and digital goods
IT stratergy and digital goodsbhavesh lande
 
Implement Mapreduce with suitable example using MongoDB.
 Implement Mapreduce with suitable example using MongoDB. Implement Mapreduce with suitable example using MongoDB.
Implement Mapreduce with suitable example using MongoDB.bhavesh lande
 
aggregation and indexing with suitable example using MongoDB.
aggregation and indexing with suitable example using MongoDB.aggregation and indexing with suitable example using MongoDB.
aggregation and indexing with suitable example using MongoDB.bhavesh lande
 
Unnamed PL/SQL code block: Use of Control structure and Exception handling i...
 Unnamed PL/SQL code block: Use of Control structure and Exception handling i... Unnamed PL/SQL code block: Use of Control structure and Exception handling i...
Unnamed PL/SQL code block: Use of Control structure and Exception handling i...bhavesh lande
 
applications and advantages of python
applications and advantages of pythonapplications and advantages of python
applications and advantages of pythonbhavesh lande
 
introduction of python in data science
introduction of python in data scienceintroduction of python in data science
introduction of python in data sciencebhavesh lande
 
data scientists and their role
data scientists and their roledata scientists and their role
data scientists and their rolebhavesh lande
 
statistics techniques to deal with data
statistics techniques to deal with datastatistics techniques to deal with data
statistics techniques to deal with databhavesh lande
 
introduction to data science
introduction to data scienceintroduction to data science
introduction to data sciencebhavesh lande
 

More from bhavesh lande (20)

The Annual G20 Scorecard – Research Performance 2019
The Annual G20 Scorecard – Research Performance 2019 The Annual G20 Scorecard – Research Performance 2019
The Annual G20 Scorecard – Research Performance 2019
 
information control and Security system
information control and Security systeminformation control and Security system
information control and Security system
 
information technology and infrastructures choices
information technology and  infrastructures choicesinformation technology and  infrastructures choices
information technology and infrastructures choices
 
ethical issues,social issues
 ethical issues,social issues ethical issues,social issues
ethical issues,social issues
 
managing inforamation system
managing inforamation systemmanaging inforamation system
managing inforamation system
 
• E-commerce, e-business ,e-governance
• E-commerce, e-business ,e-governance• E-commerce, e-business ,e-governance
• E-commerce, e-business ,e-governance
 
IT and innovations
 IT and  innovations  IT and  innovations
IT and innovations
 
organisations and information systems
organisations and  information systemsorganisations and  information systems
organisations and information systems
 
IT stratergy and digital goods
IT stratergy and digital goodsIT stratergy and digital goods
IT stratergy and digital goods
 
Implement Mapreduce with suitable example using MongoDB.
 Implement Mapreduce with suitable example using MongoDB. Implement Mapreduce with suitable example using MongoDB.
Implement Mapreduce with suitable example using MongoDB.
 
aggregation and indexing with suitable example using MongoDB.
aggregation and indexing with suitable example using MongoDB.aggregation and indexing with suitable example using MongoDB.
aggregation and indexing with suitable example using MongoDB.
 
Unnamed PL/SQL code block: Use of Control structure and Exception handling i...
 Unnamed PL/SQL code block: Use of Control structure and Exception handling i... Unnamed PL/SQL code block: Use of Control structure and Exception handling i...
Unnamed PL/SQL code block: Use of Control structure and Exception handling i...
 
working with python
working with pythonworking with python
working with python
 
applications and advantages of python
applications and advantages of pythonapplications and advantages of python
applications and advantages of python
 
introduction of python in data science
introduction of python in data scienceintroduction of python in data science
introduction of python in data science
 
tools
toolstools
tools
 
data scientists and their role
data scientists and their roledata scientists and their role
data scientists and their role
 
applications
applicationsapplications
applications
 
statistics techniques to deal with data
statistics techniques to deal with datastatistics techniques to deal with data
statistics techniques to deal with data
 
introduction to data science
introduction to data scienceintroduction to data science
introduction to data science
 

Recently uploaded

CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...Chandu841456
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage examplePragyanshuParadkar1
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixingviprabot1
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 

Recently uploaded (20)

CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage example
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixing
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 

database application using SQL DML statements: all types of Join, Sub-Query and View.

  • 1. Practical No: 4 Problem Statement: Design at least 10 SQL queries for suitable database application using SQL DML statements: all types of Join, Sub-Query and View. -------------------------------------------------------------------------------- ------------------------------- ##Sub-Query mysql> select * from emp; +-------+--------+-----------+------+------------+---------+---------+--------+ | empno | ename | job | mgr | hiredate | sal | comm | deptno | +-------+--------+-----------+------+------------+---------+---------+--------+ | 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | NULL | 20 | | 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 | | 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 | | 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | NULL | 20 | | 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 | | 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | NULL | 30 | | 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | NULL | 10 | | 7788 | SCOTT | ANALYST | 7566 | 1982-12-09 | 3000.00 | NULL | 20 | | 7839 | KING | PRESIDENT | NULL | 1981-11-17 | 5000.00 | NULL | 10 | | 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 | | 7876 | ADAMS | CLERK | 7788 | 1983-01-12 | 1100.00 | NULL | 20 | | 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | NULL | 30 | | 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | NULL | 20 | | 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | NULL | 10 | +-------+--------+-----------+------+------------+---------+---------+--------+ 14 rows in set (0.00 sec) mysql> select ename,sal,deptno from emp where deptno= (select deptno from emp where ename="SMITH"); +-------+---------+--------+ | ename | sal | deptno | +-------+---------+--------+ | SMITH | 800.00 | 20 | | JONES | 2975.00 | 20 | | SCOTT | 3000.00 | 20 | | ADAMS | 1100.00 | 20 | | FORD | 3000.00 | 20 | +-------+---------+--------+ 5 rows in set (0.00 sec) mysql> select ename,sal,deptno from emp where deptno= (select deptno from emp where ename="SMITH") and ename<>"SMITH"; +-------+---------+--------+ | ename | sal | deptno | +-------+---------+--------+ | JONES | 2975.00 | 20 | | SCOTT | 3000.00 | 20 | | ADAMS | 1100.00 | 20 | | FORD | 3000.00 | 20 | +-------+---------+--------+ 4 rows in set (0.00 sec) mysql> select ename,sal,deptno from emp where deptno= (select deptno from emp where ename="SMITH"); +-------+---------+--------+ | ename | sal | deptno | +-------+---------+--------+ | SMITH | 800.00 | 20 | | JONES | 2975.00 | 20 | | SCOTT | 3000.00 | 20 |
  • 2. | ADAMS | 1100.00 | 20 | | FORD | 3000.00 | 20 | +-------+---------+--------+ 5 rows in set (0.00 sec) mysql> select ename,sal,deptno from emp where sal> (select sal from emp where ename="SMITH"); +--------+---------+--------+ | ename | sal | deptno | +--------+---------+--------+ | ALLEN | 1600.00 | 30 | | WARD | 1250.00 | 30 | | JONES | 2975.00 | 20 | | MARTIN | 1250.00 | 30 | | BLAKE | 2850.00 | 30 | | CLARK | 2450.00 | 10 | | SCOTT | 3000.00 | 20 | | KING | 5000.00 | 10 | | TURNER | 1500.00 | 30 | | ADAMS | 1100.00 | 20 | | JAMES | 950.00 | 30 | | FORD | 3000.00 | 20 | | MILLER | 1300.00 | 10 | +--------+---------+--------+ 13 rows in set (0.00 sec) mysql> select ename,sal,deptno from emp where sal> (select sal from emp where ename="SMITH") and ename<>"SMITH"; +--------+---------+--------+ | ename | sal | deptno | +--------+---------+--------+ | ALLEN | 1600.00 | 30 | | WARD | 1250.00 | 30 | | JONES | 2975.00 | 20 | | MARTIN | 1250.00 | 30 | | BLAKE | 2850.00 | 30 | | CLARK | 2450.00 | 10 | | SCOTT | 3000.00 | 20 | | KING | 5000.00 | 10 | | TURNER | 1500.00 | 30 | | ADAMS | 1100.00 | 20 | | JAMES | 950.00 | 30 | | FORD | 3000.00 | 20 | | MILLER | 1300.00 | 10 | +--------+---------+--------+ 13 rows in set (0.00 sec) mysql> select ename,sal,deptno from emp where sal in(select sal from emp where ename="SMITH" OR ename="SCOTT" ); +-------+---------+--------+ | ename | sal | deptno | +-------+---------+--------+ | SMITH | 800.00 | 20 | | SCOTT | 3000.00 | 20 | | FORD | 3000.00 | 20 | +-------+---------+--------+ 3 rows in set (0.00 sec) mysql> select ename,sal,deptno from emp where sal in(select sal from emp where ename="SMITH" OR ename="SCOTT" ); +-------+---------+--------+ | ename | sal | deptno | +-------+---------+--------+
  • 3. | SMITH | 800.00 | 20 | | SCOTT | 3000.00 | 20 | | FORD | 3000.00 | 20 | +-------+---------+--------+ 3 rows in set (0.00 sec) mysql> select ename,sal,deptno from emp where deptno in(select deptno from emp where ename="SMITH" OR ename="SCOTT" ); +-------+---------+--------+ | ename | sal | deptno | +-------+---------+--------+ | SMITH | 800.00 | 20 | | JONES | 2975.00 | 20 | | SCOTT | 3000.00 | 20 | | ADAMS | 1100.00 | 20 | | FORD | 3000.00 | 20 | +-------+---------+--------+ 5 rows in set (0.00 sec) mysql> select ename,sal,deptno from emp where deptno in(select deptno from emp where ename="SMITH" OR ename="MILLER" ); +--------+---------+--------+ | ename | sal | deptno | +--------+---------+--------+ | SMITH | 800.00 | 20 | | JONES | 2975.00 | 20 | | CLARK | 2450.00 | 10 | | SCOTT | 3000.00 | 20 | | KING | 5000.00 | 10 | | ADAMS | 1100.00 | 20 | | FORD | 3000.00 | 20 | | MILLER | 1300.00 | 10 | +--------+---------+--------+ 8 rows in set (0.00 sec) mysql> select ename,sal,deptno from emp where deptno > ALL(select deptno from emp where ename="SMITH" OR ename="MILLER" ); +--------+---------+--------+ | ename | sal | deptno | +--------+---------+--------+ | ALLEN | 1600.00 | 30 | | WARD | 1250.00 | 30 | | MARTIN | 1250.00 | 30 | | BLAKE | 2850.00 | 30 | | TURNER | 1500.00 | 30 | | JAMES | 950.00 | 30 | +--------+---------+--------+ 6 rows in set (0.00 sec) mysql> select ename,sal,deptno from emp where deptno > ANY(select deptno from emp where ename="SMITH" OR ename="MILLER" ); +--------+---------+--------+ | ename | sal | deptno | +--------+---------+--------+ | SMITH | 800.00 | 20 | | ALLEN | 1600.00 | 30 | | WARD | 1250.00 | 30 | | JONES | 2975.00 | 20 | | MARTIN | 1250.00 | 30 | | BLAKE | 2850.00 | 30 | | SCOTT | 3000.00 | 20 | | TURNER | 1500.00 | 30 | | ADAMS | 1100.00 | 20 | | JAMES | 950.00 | 30 |
  • 4. | FORD | 3000.00 | 20 | +--------+---------+--------+ 11 rows in set (0.00 sec) mysql> select ename,sal,deptno from emp where deptno > ANY(select deptno from emp where ename="TURNER" OR ename="MILLER" ); +--------+---------+--------+ | ename | sal | deptno | +--------+---------+--------+ | SMITH | 800.00 | 20 | | ALLEN | 1600.00 | 30 | | WARD | 1250.00 | 30 | | JONES | 2975.00 | 20 | | MARTIN | 1250.00 | 30 | | BLAKE | 2850.00 | 30 | | SCOTT | 3000.00 | 20 | | TURNER | 1500.00 | 30 | | ADAMS | 1100.00 | 20 | | JAMES | 950.00 | 30 | | FORD | 3000.00 | 20 | +--------+---------+--------+ 11 rows in set (0.00 sec) mysql> select ename,sal,deptno from emp where deptno > ANY(select deptno from emp where ename="TURNER" OR ename="SCOTT" ); +--------+---------+--------+ | ename | sal | deptno | +--------+---------+--------+ | ALLEN | 1600.00 | 30 | | WARD | 1250.00 | 30 | | MARTIN | 1250.00 | 30 | | BLAKE | 2850.00 | 30 | | TURNER | 1500.00 | 30 | | JAMES | 950.00 | 30 | +--------+---------+--------+ 6 rows in set (0.00 sec) mysql> select ename,sal,deptno from emp where deptno > all(select deptno from emp where ename="TURNER" OR ename="SCOTT" ); Empty set (0.00 sec) mysql> select ename,sal,deptno from emp where sal > ANY(select sal from emp where ename="TURNER" OR ename="SCOTT" ); +-------+---------+--------+ | ename | sal | deptno | +-------+---------+--------+ | ALLEN | 1600.00 | 30 | | JONES | 2975.00 | 20 | | BLAKE | 2850.00 | 30 | | CLARK | 2450.00 | 10 | | SCOTT | 3000.00 | 20 | | KING | 5000.00 | 10 | | FORD | 3000.00 | 20 | +-------+---------+--------+ 7 rows in set (0.00 sec) mysql> select ename,sal,deptno from emp where sal > ALL(select sal from emp where ename="TURNER" OR ename="SCOTT" ); +-------+---------+--------+ | ename | sal | deptno | +-------+---------+--------+ | KING | 5000.00 | 10 | +-------+---------+--------+
  • 5. 1 row in set (0.00 sec) mysql> select ename,deptno from emp where deptno=(select deptno from dept where dname="RESEARCH"); +-------+--------+ | ename | deptno | +-------+--------+ | SMITH | 20 | | JONES | 20 | | SCOTT | 20 | | ADAMS | 20 | | FORD | 20 | +-------+--------+ 5 rows in set (0.00 sec) ##Jion mysql> create table orange(o_id varchar(20),price int(12)); Query OK, 0 rows affected (0.35 sec) mysql> create table apple(a_id varchar(20),price int(12)); Query OK, 0 rows affected (0.06 sec) mysql> insert into orange values("O1",50),("O2",60); Query OK, 2 rows affected (0.30 sec) Records: 2 Duplicates: 0 Warnings: 0 mysql> insert into apple values("A1",60),("A2",60); Query OK, 2 rows affected (0.30 sec) Records: 2 Duplicates: 0 Warnings: 0 mysql> select * from apple; +------+-------+ | a_id | price | +------+-------+ | A1 | 60 | | A2 | 60 | +------+-------+ 2 rows in set (0.00 sec) mysql> select * from orange; +------+-------+ | o_id | price | +------+-------+ | O1 | 50 | | O2 | 60 | +------+-------+ 2 rows in set (0.00 sec) mysql> select * from orange,apple; +------+-------+------+-------+ | o_id | price | a_id | price | +------+-------+------+-------+ | O1 | 50 | A1 | 60 | | O2 | 60 | A1 | 60 | | O1 | 50 | A2 | 60 | | O2 | 60 | A2 | 60 | +------+-------+------+-------+ 4 rows in set (0.00 sec) mysql> select * from orange o inner join apple a on o.price=a.price; +------+-------+------+-------+ | o_id | price | a_id | price | +------+-------+------+-------+
  • 6. | O2 | 60 | A1 | 60 | | O2 | 60 | A2 | 60 | +------+-------+------+-------+ 2 rows in set (0.04 sec) mysql> select * from orange o left outer join apple a on o.price=a.price; +------+-------+------+-------+ | o_id | price | a_id | price | +------+-------+------+-------+ | O2 | 60 | A1 | 60 | | O2 | 60 | A2 | 60 | | O1 | 50 | NULL | NULL | +------+-------+------+-------+ 3 rows in set (0.00 sec) mysql> select * from orange o right outer join apple a on o.price=a.price; +------+-------+------+-------+ | o_id | price | a_id | price | +------+-------+------+-------+ | O2 | 60 | A1 | 60 | | O2 | 60 | A2 | 60 | +------+-------+------+-------+ 2 rows in set (0.00 sec) mysql> (select * from orange o left outer join apple a on o.price=a.price) union(select * from orange o right outer join apple a on o.price=a.price); +------+-------+------+-------+ | o_id | price | a_id | price | +------+-------+------+-------+ | O2 | 60 | A1 | 60 | | O2 | 60 | A2 | 60 | | O1 | 50 | NULL | NULL | +------+-------+------+-------+