SQL Tutorial 9: SQL Joins


SQL Tutorial 9: SQL Joins

The SQL Joins clause is used to combine records from 2 or to a greater extent than tables inward a database. Influenza A virus subtype H5N1 JOIN is a agency for combining fields from 2 tables past times using values mutual to each.

Consider the next 2 tables -

Table 1 - CUSTOMERS amongst ID, NAME, AGE, as well as CITY Fields...
Table 2 - ORDERS Table amongst ID, Year, as well as Amount Fields...

Combine these 2 tables as well as exercise a Result tabular array amongst ID, NAME, as well as Amount Fields

Steps: 
//Create a Database
Create Database gcreddyDB;
------------------------
Use Database;

//Create a Table inward the Database,
Create Table Customers
(
ID int,
Name char(40),
Age int;
City char(30);
);
------------------------
//Insert Data...
Insert Into Customers(Id, Name, Age, City) 
values(1, 'Ramesh', 32, 'Hyderabad'),
(2, 'Prasad', 25, 'Delhi'),
(3, 'Venkat', 23, 'Mumbai'),
(4, 'Ramya', 25, 'Chennai');
------------------------
//Create about other table
Create Table Orders
(
OrderNo int,
Item char(30),
Amount int;
);
------------------------
//Insert Data...
Insert Into Customers(OrderNo, Item, Amount) 
values(2, 'TV', 5000),
(3, 'Fridge', 4000),
(4, 'AC', 23, 6000);
------------------------
Table 1 - Customers Table
ID
Name
Age
City
1
Ramesh
32
Hyderabad
2
Prasad
25
Delhi
3
Venkat
23
Chennai
4
Ramya
25
Mumbai

Table 2 - ORDERS Table
OrderNo
Item
Amount
2
TV
5000
3
Fridge
6000
4
AC
8000
The SQL Joins clause is used to combine records from 2 or to a greater extent than tables inward a database SQL Tutorial 9: SQL Joins
Display Tables i past times one,

Select * from Customers;
Select * from Orders;

Now, allow us bring together these 2 tables inward our SELECT tilt every bit shown below.

SQL> SELECT ID, NAME, AGE, AMOUNT
   FROM CUSTOMERS, ORDERS
   WHERE  CUSTOMERS.ID = ORDERS.OrderNo;
This would attain the next result.
ID
Name
Item
Amount
2
Prasad
TV
5000
3
Venkat
Fridge
6000
4
Ramya
AC
8000

Note: Here, it is noticeable that the bring together is performed inward the WHERE clause. Several operators tin order notice move used to bring together tables, such every bit =, <, >, <>, <=, >=, !=, BETWEEN,  LIKE, as well as NOT; they tin order notice all move used to bring together tables. However, the nearly common    operator is the equal to symbol.
------------------------------------------------------------------------
SQL Step past times Step Tutorial

1) Introduction to SQL
( )

2) SQL Overview
( )

3) MS SQL Server Installation
( )

4) Database Fundamentals as well as SQL Language Elements
( )

5) SQL Data definition Language
( )

6) SQL Data Manipulation Language
( )

7) SQL Operators
( )

8) the SQL Select Query...
(https://youtu.be/kid__0MNRps)

Sumber http://www.gcreddy.com/
Post a Comment (0)
Previous Post Next Post