Monday, May 7, 2012

SQL JOIN

Hello Friends Welcome To This where I Will Discuss about the SQL JOIN Query.

Basically JOIN is used to extract data from 2 or More tables in a Database.

Lets Make Two Tables, One Names As "Customer" and the Other as "Orders"

Customer Table

CID    Name         Designation
222    Whiskey       Moderator
444    Onty             Member
111     Gaurav         Admin
333    Kumaar        Admin
555    Rishabh        Admin
666    Rose            Admin
888    White           Member
999    Mikey          Member


Orders Table

OID    Product        CID
1         Perfume       666
2         Laptop         444
3         Perfume       999
4         Cell Phone   666


Okay so assume that these are the Two Tables, now you need to Note Something here, in the First Table the CID(Customer ID) is Unique to each record, there cannot be two records with same CID. Likewise in every table, there exists a column which holds values uniquely to the other columns. Ex: productID, SalesID, id, newsid, etc.

So similarly, the second table "Orders" has OID, which is unique, no two orders can have the same OID.

So, these are kind of keys to join tables and for other purposes, and are known as "Primary Key", So as a Conclusion, every table has got a Primary Key, through which data can be accessed and Tables can joined.

There are 4 ways By which we Join tables:

1. INNER JOIN
2. RIGHT JOIN
3. LEFT JOIN
4. FULL JOIN

Well This is all For now, Hope you liked it, Don't Forget to check my next Post.

Thank You!

0 comments:

Post a Comment