JOIN

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

JOIN

Post 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.
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post 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
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

I kinda understand...
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Post by JPlush76 »

User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post 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.
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

Thank guys... I'll understand it someday :roll:
Post Reply