---------------------------------------------------------------------------------
-- Filename
: inner_join_example01.sql
---------------------------------------------------------------------------------
-- Programmer
: Ramachandran AmmasaiGounder
-- Date
: 21-Aug-2013
-- Language
: SQL
-- Location
: Practice
-- Purpose
: This Query is simple example
for inner join using SQL
---------------------------------------------------------------------------------
-- Description :
-- Take a A B and
C tables for test.
-- write a query
for inner join
-- Check the
outputs
--
---------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
-- Update History:
-- Date
Updated By
Description
-- ---------
---------------------------
---------------------------------------------------------
-- 21-Aug-13
Ramachandran AmmasaiGounder
First version.
--
----------------------------------------------------------------------------------------------------
--Drop tables
DROP TABLE A;
DROP TABLE B;
DROP TABLE C;
/
-- Create tables
CREATE TABLE A
(
C NUMBER,
C1 VARCHAR2(10),
C2 VARCHAR2(10)
);
/
CREATE TABLE B
(
C NUMBER,
C1 VARCHAR2(10),
C2 VARCHAR2(10)
);
/
CREATE TABLE C
(
C NUMBER,
C1 VARCHAR2(10),
C2 VARCHAR2(10)
);
/
-- Insert values
INSERT INTO A
VALUES(1,'A','A');
INSERT INTO A
VALUES(2,'B','B');
INSERT INTO A
VALUES(3,'C','C');
INSERT INTO A
VALUES(4,'D','D');
/
INSERT INTO B
VALUES(1,'A','A');
INSERT INTO B
VALUES(2,'B','B');
INSERT INTO B
VALUES(3,'C','C');
INSERT INTO B
VALUES(4,'D','D');
/
INSERT INTO C
VALUES(1,'A','A');
INSERT INTO C
VALUES(2,'B','B');
INSERT INTO C
VALUES(3,'C','C');
INSERT INTO C
VALUES(4,'D','D');
COMMIT;
/
-- Joining tables in normal way
SELECT A.*, B.*, C.*
FROM A, B, C
WHERE A.C = B.C
AND A.C = C.C;
/
-- Joining tables using inner joins
SELECT A.*, B.*, C.*
FROM A A
INNER JOIN B B ON A.C = B.C
INNER JOIN C C ON A.C = C.C;
No comments:
Post a Comment