Solved

Explain JOIN

Posted on 2004-09-18
7
577 Views
Last Modified: 2013-12-12
Explain JOIN and how to use it in non mysql guru terms.
0
Comment
Question by:chilled2003
7 Comments
 
LVL 4

Accepted Solution

by:
Kaarthick earned 125 total points
ID: 12090957
Basically it is the combining of two rows based on the comparative values in selected columns.

There are various types of Join like Cross-join, Equi-join, Left Join etc

Suppose if you have names of employee in a table (EMPDETAILS)with some other columns along with the employee id. and you have another table(PAYDETAILS) with the salary information having only id and not the name of the employee.

Now if you want get the emplyee name whose salaries are greater than a particualr level you have to use Joins.

For  example the query might look like,

Select EmpName from EMPDETAILS ED,PAYDETAILS PD where ED.empid=PD.empid and pd.pay>5000
0
 

Author Comment

by:chilled2003
ID: 12090970
couldnt that be done with two querys and then use php to figure it out?  obviously the join way seems to be better but is that the main reason people use it just so mysql has to do it and so there is only one query?
0
 
LVL 49

Assisted Solution

by:Roonaan
Roonaan earned 75 total points
ID: 12090980
If you would be to join it within php you'd have loads of redundant data streaming between you phpserver and your dbserver. Besides, your dbsystem is quite optimized to perform such joins in a way you could never slightly even match with the best php code you've ever written. It's kinda like letting the carpenter do the garden and the gardeneer renting do do nothing but to say which plants are which.
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Comment

by:chilled2003
ID: 12090988
"There are various types of Join like Cross-join, Equi-join, Left Join etc"

what are the differences?
0
 
LVL 4

Assisted Solution

by:Kaarthick
Kaarthick earned 125 total points
ID: 12091030
INNER JOIN (sometimes called the "EQUI-JOIN") where tables are combined based on a common column;

OUTER JOIN which involves combining all rows of one table with only matching rows from the other table and next week's topic; and the

SELF JOIN which is a table joined to itself
0
 
LVL 27

Assisted Solution

by:Diablo84
Diablo84 earned 50 total points
ID: 12091051
There is also LEFT and RIGHT join, as i understand it...

left join selects all of the data from the first table, and then, selects only the matching results from the second table
right join selects all of the data from the second table, and then, selects only the matching results from the first table
0
 
LVL 4

Expert Comment

by:Kaarthick
ID: 12091056
CROSS JOIN - mostly it is ignored by the users.

The LEFT and RIGHT joing works as said by Diablo84.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question