Try joining parents to parentlog by left using(parent_id) . If you receive 1 row for 
student that has 2 parents (I say this because
I've never been in such situation) try to join but not left - ordinary join. So
select * from students left join parentlog using(student_id) left join parents 
using(parent_id);
or
select * from parents,parentlog left join students using(student_id) where 
parents.parent_id=parentlog.parent_id;

Hope this helps.

Andrey Hristov

----- Original Message -----
From: "John Hughes, Jomari Works" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, March 16, 2002 8:23 AM
Subject: [PHP-DB] Joining three tables


> SQL QUERY question
>
> I have three tables:
>
> students has student_id and student_name
> parents has parent_id and parent_name
> parentlog has student_id and parent_id
>
> I want to search the parentlog WHERE student_id = some_id
> GROUP BY parent_id
>
> (This will bring back two rows when there are two parents)
>
> At the same time I want to get the name of the student that
> matches student_id and the name of the parent.
>
> I can LEFT JOIN students with parentlog USING(student_id) but
> I can't figure how I can join the parents so that I can get
> the name of match for the parent_id.
>
> Can I join three tables and search all in one pass?
>
> TIA
>
> John Hughes
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to