0% found this document useful (0 votes)
8 views

Cross Join

Uploaded by

richachaube91
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Cross Join

Uploaded by

richachaube91
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

create database crossjoin;

use crossjoin;
show tables;
create table color
( colorname varchar(10) );

create table shades


(shadename varchar(10));

Insert into color values('Red'),('Green'),('Blue');


select * from color;
insert into shades values('Light'),('Cyan'),('Silver');
select * from shades;

select * from color,shades;


or
select * from color join shades;
or
select * from color cross join shades;

SELECT CONCAT( COLORNAME, ' ', SHADENAME) FROM COLOR, SHADES;

create table emp


(empno int,ename varchar(20),deptno int,salary int);

create table dept


(deptno int,dname varchar(20), dhead varchar(20));

desc emp;

desc dept;

insert into emp values


(1,'alam',10,10300);
insert into emp values
(2,'sarjeete',20,6220),
(3,'Bhaskar',30,11320),
(4,'emply',10,20500),
(5,'freddy',30,11320),
(7,'chnop',10,51100);

select * from emp;

insert into dept values


(10,'sales','ritika'),
(20,'hr','ankit'),
(30,'production','abuzair'),
(40,'IT','mesha');
select * from dept;

select * from emp,dept where emp.deptno=dept.deptno;


or
select * from emp join dept on emp.deptno=dept.deptno;

select * from emp e,dept d where e.deptno=d.deptno;

select empno,ename,emp.deptno,dname,dhead from emp,dept where


emp.deptno=dept.deptno;
select empno,ename,emp.deptno,dname,dhead from emp,dept where
emp.deptno=dept.deptno and dname='hr';

using clause

select * from emp join dept on emp.deptno=dept.deptno;


select * from emp join dept on emp.deptno=dept.deptno where salary>50000;
select * from emp natural join dept;

You might also like