Reply to Re: Looping through 2 query results

Your name:

Reply:


Posted by Kenoli on 02/10/07 04:11

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,

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация