Foros del Web » Programación para mayores de 30 ;) » Bases de Datos General » Mysql »

consulta BD me devuelve demasiados resultados

Estas en el tema de consulta BD me devuelve demasiados resultados en el foro de Mysql en Foros del Web. hola ... tengo la siguiente BD... la cosa es que al buscar por nombre de articulo se me disparan la cantidad de resultados... se asocian ...
  #1 (permalink)  
Antiguo 22/02/2008, 12:48
 
Fecha de Ingreso: febrero-2008
Mensajes: 73
Antigüedad: 16 años, 2 meses
Puntos: 0
consulta BD me devuelve demasiados resultados

hola ...
tengo la siguiente BD... la cosa es que al buscar por nombre de articulo se me disparan la cantidad de resultados... se asocian valores que no deberian... quien me puede ayudar en realizar la consulta sobre un nombre de articulo, donde:

dado un nombre de articulo se despliegue info empresa, pais, cliente... todo y obviamnete los valores respectivos de ese articulo

Código:
/*==============================================================*/
/* DBMS name:      MySQL 5.0                                    */
/* Created on:     21/02/2008 9:59:55                           */
/*==============================================================*/


drop table if exists ARTICULO;

drop table if exists CLIENTE;

drop table if exists DETALLE;

drop table if exists EMPRESA;

drop table if exists FORMULARIO;

drop table if exists PAIS;

drop table if exists VALORES_ARTICULO;

drop table if exists VALOR_ARTICULO;

/*==============================================================*/
/* Table: ARTICULO                                              */
/*==============================================================*/
create table ARTICULO
(
   ARTICULO_COD         varchar(10) not null,
   ARTICULO_NOMBRE      varchar(30),
   ARTICULO_CLASIF      text,
   primary key (ARTICULO_COD)
);

/*==============================================================*/
/* Table: CLIENTE                                               */
/*==============================================================*/
create table CLIENTE
(
   CLIENTE_RUT          varchar(10) not null,
   CLIENTE_NOMBRE       char(50),
   CLIENTE_DSC          text,
   primary key (CLIENTE_RUT)
);

/*==============================================================*/
/* Table: DETALLE                                               */
/*==============================================================*/
create table DETALLE
(
   ARTICULO_COD         varchar(10) not null,
   FORMULARIO_COD       varchar(20) not null
);

/*==============================================================*/
/* Table: EMPRESA                                               */
/*==============================================================*/
create table EMPRESA
(
   EMPRESA_COD          varchar(10) not null,
   PAIS_COD             int not null,
   EMPRESA_NOMBRE       varchar(20),
   primary key (EMPRESA_COD)
);

/*==============================================================*/
/* Table: FORMULARIO                                            */
/*==============================================================*/
create table FORMULARIO
(
   FORMULARIO_COD       varchar(20) not null,
   CLIENTE_RUT          varchar(10) not null,
   EMPRESA_COD          varchar(10) not null,
   primary key (FORMULARIO_COD)
);

/*==============================================================*/
/* Table: PAIS                                                  */
/*==============================================================*/
create table PAIS
(
   PAIS_COD             int not null,
   PAIS_NOMBRE          varchar(20),
   primary key (PAIS_COD)
);

/*==============================================================*/
/* Table: VALORES_ARTICULO                                      */
/*==============================================================*/
create table VALORES_ARTICULO
(
   ARTICULO_COD         varchar(10) not null,
   VALOR_COD            int not null
);

/*==============================================================*/
/* Table: VALOR_ARTICULO                                        */
/*==============================================================*/
create table VALOR_ARTICULO
(
   ARTICULO_VALOR1      float,
   ARTICULO_VALOR2      float,
   ARTICULO_VALOR3      float,
   VALOR_COD            int not null,
   primary key (VALOR_COD)
);

alter table DETALLE add constraint FK_RELATIONSHIP_3 foreign key (FORMULARIO_COD)
      references FORMULARIO (FORMULARIO_COD) on delete restrict on update restrict;

alter table DETALLE add constraint FK_RELATIONSHIP_4 foreign key (ARTICULO_COD)
      references ARTICULO (ARTICULO_COD) on delete restrict on update restrict;

alter table EMPRESA add constraint FK_RELATIONSHIP_6 foreign key (PAIS_COD)
      references PAIS (PAIS_COD) on delete restrict on update restrict;

alter table FORMULARIO add constraint FK_RELATIONSHIP_2 foreign key (EMPRESA_COD)
      references EMPRESA (EMPRESA_COD) on delete restrict on update restrict;

alter table FORMULARIO add constraint FK_RELATIONSHIP_5 foreign key (CLIENTE_RUT)
      references CLIENTE (CLIENTE_RUT) on delete restrict on update restrict;

alter table VALORES_ARTICULO add constraint FK_RELATIONSHIP_7 foreign key (ARTICULO_COD)
      references ARTICULO (ARTICULO_COD) on delete restrict on update restrict;

alter table VALORES_ARTICULO add constraint FK_RELATIONSHIP_8 foreign key (VALOR_COD)
      references VALOR_ARTICULO (VALOR_COD) on delete restrict on update restrict;
Recuerden dado un nombre de articulo retornar toda la info relacionada con cliente, empresa y valores...

gracias
  #2 (permalink)  
Antiguo 24/02/2008, 08:57
 
Fecha de Ingreso: mayo-2006
Mensajes: 120
Antigüedad: 18 años
Puntos: 3
Re: consulta BD me devuelve demasiados resultados

Me ha costado seguirte, quizá si pusieras algunos inserts y el resultado esperado podría hacer un poco más.

Por el momento creo que la idea te tiene que servir:
Código:
SELECT CLIENTE.CLIENTE_NOMBRE, 
       EMPRESA.EMPRESA_NOMBRE,
       PAIS.PAIS_NOMBRE,
       VALOR_ARTICULO.ARTICULO_VALOR1,
       VALOR_ARTICULO.ARTICULO_VALOR2,
       VALOR_ARTICULO.ARTICULO_VALOR3
       FROM ARTICULO
       LEFT JOIN DETALLE ON ARTICULO.ARTICULO_COD = DETALLE.ARTICULO_COD
       LEFT JOIN FORMULARIO ON FORMULARIO.FORMULARIO_COD = DETALLE.FORMULARIO_COD
       LEFT JOIN CLIENTE ON CLIENTE.CLIENTE_RUT = FORMULARIO.CLIENTE_RUT
       LEFT JOIN EMPRESA ON FORMULARIO.EMPRESA_COD = EMPRESA.EMPRESA_COD
       LEFT JOIN PAIS ON EMPRESA.PAIS_COD = PAIS.PAIS_COD         
       LEFT JOIN VALORES_ARTICULO ON VALORES_ARTICULO.ARTICULO_COD = ARTICULO.ARTICULO_COD
       LEFT JOIN VALOR_ARTICULO ON VALOR_ARTICULO.VALOR_COD =  VALORES_ARTICULO.VALOR_COD
       WHERE ARTICULO_NOMBRE = 'PEPE' ;
Suerte con esta gran base de datos :D
__________________
programación php
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 20:20.