|
Posted by Captain Paralytic on 02/12/07 09:56
On 10 Feb, 04:11, "Kenoli" <kenol...@gmail.com> wrote:
> On Feb 9, 7:03 am, "J.O. Aho" <u...@example.net> wrote:
>
>
>
>
>
> > Kenoli wrote:
> > > I get the error:
> > > MySQL Error: Column 'person_id' in where clause is ambiguous
>
> > This happens sometimes when you have tables with the same column names, you
> > have to specify which tables person_id you are going to use
>
> > In your case it would be tbl_person.person_id or tbl_contact_info.person_id
>
> > IMHO it's always good to specify a columns table when using joins, you get a
> > lot less of these errors that way and you easilly know from which table a
> > column is when you look at the query.
>
> > $query = "SELECT * FROM tbl_person JOIN tbl_contact_info USING
> > (person_id) WHERE person_id = '5' OR person_id = '6';";
>
> > would become:
>
> > $query = "SELECT * FROM tbl_person JOIN tbl_contact_info ON
> > (tbl_person.person_id=tbl_contact_info.person_id) WHERE tbl_person.person_id
> > = '5' OR tbl_person.person_id = '6'";
>
> > Yes, it will be a bit longer to type, but will work better.
>
> > --
>
> > //Aho
>
> Great! It works I'm curious that it works to point it only at the
> person_id in one table, since the match actually applies to both
> tables. Would it do the same thing if I pointed it at the other
> table?
>
> At any rate, it's a great shortcut.
>
> Does anyone know a good online tutorial or other resource on joins.
> The MySQL manual might as well be written in Greek for all I've been
> able to make of it. I don't even see the join described here in the
> manual.
>
> For some reason, the concept in general has been hard for me to get,
> though this example is straightforward and intuitive and exactly what
> I was looking for.
>
> I also tried out UNION, with no sucess, though I don't think it was
> what I wanted anyway.
>
> --Kenoli
>
> Thanks,- Hide quoted text -
>
> - Show quoted text -
Your match conditions say
"tbl_person.person_id=tbl_contact_info.person_id" or the shortcut of
USING(person_id).
This condition says that the values of person_id in both tables must
be the same. So it doesnt' matter which one you "point to", as the
match condition will make it "point to" both of them.
Navigation:
[Reply to this message]
|