Try

SELECT teams.*, divisions.id AS divisonid, divisions.name AS divisionname
FROM teams LEFT JOIN divisions ON teams.divisonID = divisions.divisionID

if the ids are the same you can actually also write

ON teams.divisonID

and omit

= divisions.divisionID

... I think.


hth

toby
> I'm looking for a good way to do the following:
>
> I have two tables, one named teams and one named divisions.
> Divisions relates divisionID to the name of the division
> (division_name).  In teams I have the divisionID stored
> along with the team_name.  [BG info: teams can be relegated
> or promoted so it's easier for me to store the divID in
> the teams table] I'd like to populate a drop down menu with
> the team_name and division_name and was wondering if I can
> do some kind of select statement that will get all the info
> at once with the following details on the two tables:
>
> mysql> select * from teams;
>
+--------+-----------+---------+------------+------+------------+-----+-----
-+-----+-----------+---------------+
> | teamID | team_name | coachID | divisionID | paid | pmnt_notes | win |
loss | tie | goals_for | goals_against |
>
+--------+-----------+---------+------------+------+------------+-----+-----
-+-----+-----------+---------------+
> |      1 | Metro     |       0 |          1 | n    | NULL       |   0 |
0 |   0 |         0 |             0 |
>
+--------+-----------+---------+------------+------+------------+-----+-----
-+-----+-----------+---------------+
> 1 row in set (0.00 sec)
>
> mysql> select * from divisions;
> +------------+------------------+
> | divisionID | division_name    |
> +------------+------------------+
> |          1 | Premier          |
> |          2 | Classic          |
> |          3 | Recreational 7v7 |
> +------------+------------------+
> 3 rows in set (0.00 sec)
>
> Thanks in advance!
> Kirk
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

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

Reply via email to