🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: chile.comp.programacion
Article #1478

Re: problema join con mysql

#1478
From: Jos� Miguel Santib��ez
Date: Sat, 05 Aug 2006 04:53
41 lines
2735 bytes
En el cap�tulo anterior (news:eb0aea$1bh$1@news.nivel5.cl), "Rick_oj"
<rick_oj@[sin-esto]tutopia.com> dijo: 

> tengo las siguientes tablas
> CREATE TABLE `clientes` (
>   `rut` int(9) NOT NULL,
>   `ap_paterno` varchar(50) NOT NULL,
>   `ap_matern` varchar(50) NOT NULL,
>   `nombres` varchar(100) NOT NULL,
>   `compra` varchar(10) NOT NULL,
>   UNIQUE KEY `rut` (`rut`)
> ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
> 
> CREATE TABLE `productos` (
>   `rut` int(9) NOT NULL,
>   `items` varchar(1) NOT NULL,
>   // otros campos//
>  UNIQUE KEY `rut` (`rut`)
> ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
> 
> y la siguiente sentencia sql
> SELECT `ap_paterno`,`ap_matern`,`clientes`.`rut`,`items`
> FROM clientes c join productos p
> WHERE c.rut=p.rut and c.compra='efectuada'
> 
> mysql responde "rut is ambigous" por que el rut es el mismo en ambas
> tablas se que si hago select * from.... funciona
> el asunto es que no me interesa rescatar los "otros campos", ahora
> podria rescatarlos y no despleglarlos pero no es la idea
> 

tu mismo te das la respuesta: el rut del select es el que causa ambiguedad 
(a�n cuando debieran ser iguales)... Por lo tanto debes decidir cual de los 
dos es el que quieres c.rut o p.rut (ya que tienes los alias, que dicho sea 
de paso, creo que no se justifican para nada, al igual que la palabra join, 
que reemplazar�a por una coma).

-- 
Apoye a la campa�a de alfabetizaci�n y  |       Jose M. Santiba�ez A.
ordenaci�n de las news, cada post en su |          <jms@nivel5.cl>
lugar y el lugar exacto para cada post  |        <http://caos.cl/jms>
Technical Details
Message-ID: <Xns9816122D877E0jmsnews@200.27.221.71>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news.glorb.com!nntp-server.pubsub.com!news.nivel5.cl!news.vcd.cl!not-for-mail!not-for-mail
References: <eb0aea$1bh$1@news.nivel5.cl>

Show Full Headers
Complete Article Headers
X-Google-Thread: 1593cb,599d380b0a5f3acc
X-Google-Attributes: gid1593cb,public
X-Google-Language: SPANISH,ASCII
Newsgroups: chile.comp.programacion
Subject: Re: problema join con mysql
From: "Jos� Miguel Santib��ez" <jms.nospam@nivel5.cl>
References: <eb0aea$1bh$1@news.nivel5.cl>
Organization: Caos Consultores
Message-ID: <Xns9816122D877E0jmsnews@200.27.221.71>
User-Agent: Xnews/5.04.25
X-Face: +|NgjgFM{<rs%\Q|vUu16]a6,}?MJTA<!PEEI+x&Gw-Gyq+?$}fvo+.(,-r;)~Qzn)#{{nxU,OT?w^s<7m4ckCJ*L$c#I)yHL7b)GdU*#l
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
NNTP-Posting-Host: 177-38-246-201.adsl.terra.cl
X-Original-NNTP-Posting-Host: 177-38-246-201.adsl.terra.cl
Date: 5 Aug 2006 00:53:38 -0400
X-Trace: news.vcd.cl!not-for-mail 1154753618 201.246.38.177 (5 Aug 2006 00:53:38 -0400)
X-Original-Trace: 5 Aug 2006 00:53:38 -0400, 177-38-246-201.adsl.terra.cl
Lines: 41
X-Authenticated-User: jms
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news.glorb.com!nntp-server.pubsub.com!news.nivel5.cl!news.vcd.cl!not-for-mail!not-for-mail