Re: [PHP] Ambiguous?

[email protected] (Floyd Resler)
Newsgroups php.general
Message-ID <[email protected]>

On Aug 9, 2013, at 8:00 AM, Karl-Arne Gjersøyen <[email protected]> wrote:

> 1) query
> foreach($varenr_inn_pa_lager as $vnr){
>            include('../../tilkobling.php');
>            $sql = "SELECT * FROM exan,dynamit WHERE varenr = '$vnr' LIMIT
> 1";
>            $resultat = mysql_query($sql, $tilkobling) or
> die(mysql_error());
> 
> 2) Result:
> Column 'varenr' in where clause is ambiguous
> 
> 3) Tables in MySQL database
> 
> mysql> SELECT * FROM exan;
> +------------+-------------+-------+----------+----------+-------------+
> | leverandor | valgt_lager | un_nr | varenavn | varenr   | kg_pa_lager |
> +------------+-------------+-------+----------+----------+-------------+
> 
> mysql> SELECT * FROM dynamit;
> +------------+-------------+---------------+--------+-------+---------------------+------------+-------------+
> | leverandor | valgt_lager | type          | dim_mm | un_nr |
> varenavn            | varenr     | kg_pa_lager |
> +------------+-------------+---------------+--------+-------+---------------------+------------+-------------+
> 
> 4) My question:
> What means with "ambiguous" here?
> 
> Thanks.
> Karl

Your field "varenr" is in both tables you are joining.  Therefore, MySQL doesn't know which table it should use the field from.  So, you need to qualify it by putting the table name in front of the field.  Such as:
SELECT * FROM exan,dynamit WHERE exan.varenr='$vnr' LIMIT 1

Take care,
Floyd
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.