Article View: chile.comp.programacion
Article #3310Re: consulta mysql
From: Rickoj
Date: Fri, 08 Apr 2005 15:43
Date: Fri, 08 Apr 2005 15:43
85 lines
3687 bytes
3687 bytes
En las news:Xns963215357D2F6jmsnews@200.27.221.71, a Jos� Miguel Santib��ez
se le ocurrio
tipear:
> En el cap�tulo anterior (news:d356cj$l4q$1@news1.nivel5.cl), "Rick_oj"
> <rick_oj@[sin-esto]tutopia.com> dijo:
>
>> En las news:Xns9632115AD8204jmsnews@200.27.221.71, a Jos� Miguel
>> Santib��ez se le ocurrio
>> tipear:
>>> En el cap�tulo anterior (news:d34hfe$e77$1@news1.nivel5.cl),
>>> "Rick_oj" <rick_oj@[sin-esto]tutopia.com> dijo:
>>>
>>>> tengo la siguiente situacion (parecida)
>>>> una tabla con compras por clientes para dicho articulo
>>>> como puedo seleccionar que clientes no compro el articulo x,
>>>> existe un where not? (toy medio oxidado con bdd)
>>>>
>>>>
>>>
>>> algo as�:
>>>
>>> CREATE TABLE `master` (
>>> `numero` varchar(20) NOT NULL default '0',
>>> `cliente` tinytext NOT NULL,
>>> `fecha` tinytext,
>>> PRIMARY KEY (`numero`),
>>> KEY `numero` (`numero`)
>>> );
>>>
>>> INSERT INTO `master` (`numero`, `cliente`, `fecha`)
>>> VALUES ('v1', 'lala', '2005-04-08'),
>>> ('v2', 'lele', '2005-04-08'),
>>> ('v3', 'lili', '2005-04-08'),
>>> ('v4', 'lolo', '2005-04-08');
>>>
>>>
>>> CREATE TABLE `detalle` (
>>> `numero` varchar(20) NOT NULL default '0',
>>> `producto` int(11) NOT NULL default '0',
>>> `cantidad` tinyint(4) NOT NULL default '1',
>>> `precio` int(11) default NULL,
>>> PRIMARY KEY (`numero`,`producto`),
>>> KEY `numprod` (`numero`,`producto`),
>>> KEY `producto` (`producto`)
>>> );
>>>
>>> INSERT INTO `detalle` (`numero`, `producto`, `cantidad`, `precio`)
>>> VALUES ('v1', 1, 1, 10),
>>> ('v1', 2, 1, 10),
>>> ('v1', 3, 1, 10),
>>> ('v2', 1, 1, 10),
>>> ('v3', 1, 1, 10),
>>> ('v3', 2, 1, 10),
>>> ('v4', 2, 1, 10),
>>> ('v4', 3, 10, 100);
>>>
>>>
>>> SELECT cliente
>>> FROM master left join detalle on master.numero = detalle.numero
>>> and producto=3
>>> where producto is null
>>>
>>> resultado:
>>>
>>> lele y lili
>>
>> con solo una tabla no se puede? si producto is not null en la tabla
>> como
>> puede el select ser where is null, me quedo esa duda mirando el manual
>> de mysql (hace demasiado que vi sql)
>>
>>
>
> A ver, si lo quieres hacer usando solo la tabla detalle (agreg�ndo ah� el
> cliente):
>
> SELECT distinct t1.numero
> FROM detalle AS t1
> LEFT JOIN detalle AS t2 ON t1.numero = t2.numero AND t2.producto =3
> WHERE t2.producto IS NULL
>
> (claro que tendr�a que ser t1.cliente, pero no quise cambiarlo para que
> funcione con lo de arriba)
voy a probarlo creo que la cosa era select distinct
Technical Details
Message-ID:
<d3690c$t78$1@news1.nivel5.cl>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!nntp-server.pubsub.com!news1.nivel5.cl!not-for-mailReferences:
<d34hfe$e77$1@news1.nivel5.cl> <Xns9632115AD8204jmsnews@200.27.221.71> <d356cj$l4q$1@news1.nivel5.cl> <Xns963215357D2F6jmsnews@200.27.221.71>Show Full Headers
Complete Article Headers
X-Google-Thread: 1593cb,9070da774c101bc6 X-Google-Attributes: gid1593cb,public X-Google-Language: SPANISH,ASCII Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!nntp-server.pubsub.com!news1.nivel5.cl!not-for-mail From: "Rick_oj" <rick_oj@[sin-esto]tutopia.com> Newsgroups: chile.comp.programacion Subject: Re: consulta mysql Date: Fri, 8 Apr 2005 11:43:54 -0400 Organization: Varios Lines: 87 Message-ID: <d3690c$t78$1@news1.nivel5.cl> References: <d34hfe$e77$1@news1.nivel5.cl> <Xns9632115AD8204jmsnews@200.27.221.71> <d356cj$l4q$1@news1.nivel5.cl> <Xns963215357D2F6jmsnews@200.27.221.71> NNTP-Posting-Host: pc-97-201-120-200.cm.vtr.net X-Trace: news1.nivel5.cl 1112975180 29928 200.120.201.97 (8 Apr 2005 15:46:20 GMT) X-Complaints-To: news@news1.nivel5.cl NNTP-Posting-Date: Fri, 8 Apr 2005 15:46:20 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1478 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1478