Search Marketing

   
   

How to Create a MySQL Inner Join Query

Fri May 02, 2008 9:54 pm
<<     >>
Comments: 0 Views: 6923

MySQL is a relational database capable of many useful tasks. The Join, Inner and Left, are both ways of dealing with extracting data from a table or series of tables.

The simplest type of Join is the inner join. The type of Join allows you to get the proper data from either one table or multiple tables.

If you strart with three tables structured in this fashion:

customer_data total_invoice_data invoice_data
ID
Name
Address
ID
Date
TotalPrice
ID
Items
Price

To retrieve the total invoice information from any given customer you need to link together the various table information.

If the first table has a list of our customers, the second table has each invoice they have generated, and the third table has each item or product that is associated with each invoice event, then we must find a way to group the data together to make sense.

First lets find out how many total invoices exist for a given customer.

select count(tid.ID)
from customer_data cd, total_invoice_data tid
where cd.ID=tid.ID && cd.ID=someid;

If we now want to find out what a complete invoice looks like for a given invoice:

select id.Items,id.Price
from total_invoice_data tid, invoice_data id
where tid.ID=id.ID && tid.ID=someid;

Inner Joins are very simple and allow you to seperate your data into many tables for easier organization.



Comments
Name:
*
URL: http: (ex. cnn.com)
Comment:
*
Number:
Math (26 + 2)
* required
SubCategories
Books

© 2017 Christonium LLC

Christonium.com
|
Terms of Use
|
Privacy
ccc