Page 1 of 1

JOIN

Posted: Mon Aug 26, 2002 12:52 am
by Takuma
Could anyone tell me what "JOIN" does in MySQL. I've read the book and manual but do not understand... Also could you tell me where I can make use of this command.

Posted: Mon Aug 26, 2002 5:27 am
by mikeq
It is not just JOIN on its own you use it with Left, Right (Outer?) and it is used within the from clause

select *
from firsttable LEFT JOIN secondtable ON firsttable.fieldid = secondtable.fieldid

This will produce a result query with all records from 1 table and records in the second table where there is a match, so if there is no match for a record the information from the first table will be output with nulls output for the second table

Posted: Mon Aug 26, 2002 3:04 pm
by Takuma
I kinda understand...

Posted: Mon Aug 26, 2002 3:15 pm
by JPlush76

Posted: Mon Aug 26, 2002 3:22 pm
by nielsene
Some of what you can do with JOIN's in the FROM clause can be done with stuff in the WHERE claues (ie all inner joins). LEFT,RIGHT,FULL OUTER JOIN's are only possibly in the FROM or by using nasty UNIONs of seperate queries. A comma ',' in the FROM list is equal to a "CROSS JOIN". JOIN is usable by itself normally as in table1 JOIN table2 ON (table1.field = table2.field) and is an implied inner join.

Fundamentally JOINs are about building up the set of valid rows to select data from and WHEREs are about removing items from the list of valid rows. Using both JOINs and WHERE clauses effectively can make queries much more understandable.

Posted: Mon Aug 26, 2002 3:28 pm
by Takuma
Thank guys... I'll understand it someday :roll: