|
Posted by Rik on 02/08/07 17:37
Kenoli <kenoli.p@gmail.com> wrote:
> On Feb 8, 2:00 am, "Captain Paralytic" <paul_laut...@yahoo.com> wrote:=
>>
>> If the results are linked by a common column then query using a JOIN
>> between the tables thus:
>>
>> SELECT *
>> FROM table1
>> JOIN table2 USING(person_id)
>> WHERE .....
>>
>> Then all your results are in single rows based on person_id
>
> This sounds exactly what I would like to do but haven't been able to
> get to work. Here is the query based on your format applied to my
> tables with the php code:
>
> $query =3D "SELECT * FROM tbl_person JOIN tbl_contact_info USING
> (person_id) WHERE person_id =3D '5' OR person_id =3D '6';";
>
> $result =3D mysql_query ($query);
>
> if (!$result) {echo "<br/><br/>You screwed up!";} else {echo "<br/><br=
/
>> You succeeded!<br/><br/>";}
Please echo mysql_error(), it's much more informative then 'You screwed =
=
up!' ;P
I always like to:
1. Name every desired field explicitly.
2. Use explicit joins.
So that would mean:
SELECT
a.`field1`, a.`field2`, b.`field3`
FROM `tbl_person` a
JOIN `tbl_contact_info` b
ON a.`person_id` =3D b.`person_id`
WHERE `person_id` IN (5,6)
-- =
Rik Wasmus
Navigation:
[Reply to this message]
|