On Thu, 4 Sep 2003 13:57:53 -0500, Darryl Hoar <[EMAIL PROTECTED]> wrote:

Joins can in fact be rather confusing at first. The MySQL manual doesn't help out much, either, I'm afraid. There are lots of good references available though. I don't know of any online right off hand, but _SQL Queries for Mere Mortals_ (Hernandez and Viescas) is a very good book.

Anyway, try this:

  SELECT *
  FROM employee
    JOIN emp2 ON employee.field1 = emp2.field3

This will give a combination of all columns from both tables where the ON condition holds true.

To restrict the columns returned, change the * to list the columns.

To get all employees with NULL for those who don't have an entry in emp2 change the JOIN to a LEFT JOIN.

Hope this helps.
Michael

Greetings,
I am just trying to wrap my brain around joins.

I have a table employee. For each record in employee, I want to see
if a record exists in table emp2 based on a field value in both tables. IE,


for each employee
  for each emp2
     if employee.field1 = emp2.field3 then
        do something interesting.
   end emp2 loop
end employee loop.


can someone point me to the right join syntax to get this done ?


thanks,
Darryl





-- Michael Johnson < [EMAIL PROTECTED] > Internet Application Programmer, Pitsco, Inc. 620-231-2424x516

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to