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

Dbms Lab Assignments-6

The document describes SQL joins, which are used to retrieve data from multiple tables. There are four types of SQL joins: inner join, left outer join, right outer join, and full outer join. An inner join returns rows where there is a match in both tables on the join condition.

Uploaded by

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

Dbms Lab Assignments-6

The document describes SQL joins, which are used to retrieve data from multiple tables. There are four types of SQL joins: inner join, left outer join, right outer join, and full outer join. An inner join returns rows where there is a match in both tables on the join condition.

Uploaded by

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

ASSIGMENT-7

JOINING
DESCRIPTION

SQL JOINS are used to retrieve data from multiple tables. A SQL JOIN is performed whenever two or more
tables are joined in a SQL statement.

There are 4 different types of SQL joins:

SQL INNER JOIN (or sometimes called simple join)


SQL LEFT OUTER JOIN (or sometimes called LEFT JOIN)
SQL RIGHT OUTER JOIN (or sometimes called RIGHT JOIN)
SQL FULL OUTER JOIN (or sometimes called FULL JOIN)

SQL INNER JOIN (SIMPLE JOIN)

It is the most common type of SQL join. SQL INNER JOINS return all rows from multiple tables where the join
condition is met.

The syntax for the SQL INNER JOIN is:

SELECT columns FROM table1 INNER JOIN table2 ON table1.column = table2.column;

Visual Illustration
In this visual diagram, the SQL INNER JOIN returns the shaded area:

The SQL INNER JOIN would return the records where table1 and table2 intersect.
1) Create a table called suppliers with two fields’ supplier_id and supplier_name and insert the following
data:

supplier_id supplier name


10000 IBM
10001 Hewlett Packard
10002 Microsoft
10003 NVIDIA
2) Create a table called orders with three fields’ order_id, supplier_id, and order_dateand the following
data:
order_id supplier_id order_date
500125 10000 2003/05/12
500126 10001 2003/05/13
500127 10004 2003/05/14
3) Select supplier_id,supplier_name and order_datefromsuppliers and orders table using JOIN.

4) Create a table called titleswith following fields

title_id varchar(20)
title varchar(80)
type char(12)
pub_id char(4)
price integer
advance integer
royalty integer
notes varchar(200)
pubdate datetime

5) Insert the following data:-

'1' 'Secrets' 'popular_comp' '1389' $20.00 $8000.00 8 'Note 1' '06/12/94'


'2' 'The' 'business' '1389' $19.99 $5000.00 10 'Note 2' '06/12/91'
'3' 'Emotional' 'psychology' '0736' $7.99 $4000.00 9 'Note 3' '06/12/91'
'4' 'Prolonged' 'psychology' '0736' $19.99 $2000.00 6 'Note 4' '06/12/91'
'5' 'With' 'business' '1389' $11.95 $5000.00 14 'Note 5' '06/09/91'
'6' 'Valley' 'mod_cook' '0877' $19.99 $0.00 12 'Note 6' '06/09/91'
'7' 'Any?' 'trad_cook' '0877' $14.99 $8000.00 10 'Note 7' '06/12/91'
'8' 'Fifty' 'trad_cook' '0877' $11.95 $4000.00 12 'Note 8' '06/12/91'

6) Create a table called authorswith following fields


au_id varchar(11)
au_lname varchar(40)
au_fname varchar(20)
phone char(12)
address varchar(40)
city varchar(20)
state char(2)
zip char(5)
contract Integer
7) Insert the following data:-

'1', 'Joe', 'Abra', '111 111-1111', '6 St.', 'Berkeley', 'CA', '11111', 1
'2', 'Jack', 'Majo', '222 222-2222', '3 St.', 'Oakland' , 'CA', '22222', 1
'3', 'Pink', 'Cherry', '333 333-3333', '5 Ln.', 'Vancouver', 'BC', '33333', 1
'4', 'Blue', 'Albert', '444 444-4444', '7 Av.', 'Vancouver', 'BC', '44444', 1
'5', 'Red', 'Anne', '555 555-5555', '6 Av.', 'Regina', 'SK', '55555', 1
8) Select au_lname, titlefrom authors and titles table using Join.
9) Select pub_id, price, contract fromauthors and titles table using Join.
10) Select title_id, type, au_lnamefrom authors and titles table where typebelongs topsychology.
11) Select title_id, title, au_lname,royaltyfrom authors and titles table whereroyaltybetween 10 to 14.
12) Select title, city, royaltyfrom authors and titles table wherepub_idbelongs to0877androyaltybelongs
to12.
13) Select au_id ,au_lname, title, pricefrom authors and titles table wherestatebelongs toCA Order By
address .

You might also like