consultar tablas con LEFT JOIN Hola a todos, y a ver si teneis alguna solución con mi problema ya que no saco el porque no me funciona.
tengo esta consulta para una BBDD MySQl: Código PHP: SELECT * FROM articulo LEFT JOIN articulo,categoria,marca,modelo,tipo ON id_art = articulo.id_art tipo = tipo_es categoria = categoria_es modelo = modelo_es marca = marca_es precio = precio descripcion_es = descripcion_es descripcion_en = descripcion_en nombreimagen1 = nombreimagen1 LA BASE DE DATOS ES ESTA: Código PHP: /* SQLyog Community Edition- MySQL GUI v5.22a Host - 4.0.27-log : Database - nombrebasedatos ********************************************************************* Server version : 4.0.27-log */ create database if not exists `basedatos`; USE `basedatos`; /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; /*Table structure for table `articulo` */ DROP TABLE IF EXISTS `articulo`; CREATE TABLE `articulo` ( `id_art` int(6) NOT NULL default '0', `tipo` char(2) NOT NULL default '0', `cat` char(2) NOT NULL default '0', `model` char(2) NOT NULL default '0', `marca` char(2) NOT NULL default '0', `precio` int(7) default NULL, `descripcion_es` text NOT NULL, `descripcion_en` text NOT NULL, `nombreimagen1` varchar(50) NOT NULL default '', `fecha` date NOT NULL default '0000-00-00', `ultimamodificacion` timestamp(14) NOT NULL, PRIMARY KEY (`id_art`), UNIQUE KEY `nombreimagen1` (`nombreimagen1`), FULLTEXT KEY `buscar` (`descripcion_es`,`descripcion_en`) ) TYPE=MyISAM; /*Data for the table `articulo` */ insert into `articulo`(`id_art`,`tipo`,`cat`,`model`,`marca`,`precio`,`descripcion_es`,`descripcion_en`,`nombreimagen1`,`fecha`,`ultimamodificacion`) values (4,'1','1','2','2',5455,'Barco estupendo en el que se pu\r\n','descripcion en ingles','nombreimg.jpg','0000-00-00',20070917130817),(5,'1','2','1','1',232,'un poco mas pequeño','en ingles','otra.jpg','0000-00-00',20070917131212); /*Table structure for table `categoria` */ DROP TABLE IF EXISTS `categoria`; CREATE TABLE `categoria` ( `id_cat` int(2) unsigned NOT NULL auto_increment, `categoria_es` varchar(50) NOT NULL default '', `categoria_en` varchar(50) NOT NULL default '', `des_cat` varchar(255) default NULL, PRIMARY KEY (`id_cat`,`categoria_es`,`categoria_en`), UNIQUE KEY `id_cat` (`id_cat`) ) TYPE=MyISAM; /*Data for the table `categoria` */ insert into `categoria`(`id_cat`,`categoria_es`,`categoria_en`,`des_cat`) values (1,'Nuevo','New','Artículos nuevos'),(2,'Usado','Used','Artículo usado'); /*Table structure for table `marca` */ DROP TABLE IF EXISTS `marca`; CREATE TABLE `marca` ( `id_marca` int(3) unsigned NOT NULL auto_increment, `marca_es` varchar(50) default NULL, PRIMARY KEY (`id_marca`) ) TYPE=MyISAM; /*Data for the table `marca` */ insert into `marca`(`id_marca`,`marca_es`) values (1,'Honda'),(2,'Yamaha'),(3,'Seadoo'); /*Table structure for table `modelo` */ DROP TABLE IF EXISTS `modelo`; CREATE TABLE `modelo` ( `id_model` int(2) unsigned NOT NULL auto_increment, `model_tipo` int(2) default NULL, `modelo_es` varchar(50) NOT NULL default '', `modelo_en` varchar(50) NOT NULL default '', `des_modelo` varchar(255) default NULL, PRIMARY KEY (`id_model`) ) TYPE=MyISAM; /*Data for the table `modelo` */ insert into `modelo`(`id_model`,`model_tipo`,`modelo_es`,`modelo_en`,`des_modelo`) values (1,1,'Eslora 3-6m','Slora 3-6m',NULL),(2,1,'Eslora 7-10 m','Slora 7-10m',NULL),(3,1,'Eslora 10-20m','Slora 10-20m',NULL),(4,1,'Eslora +20m','Slora +20m',NULL),(5,2,'Motor 4t/Gasolina','4t/Gasolina Engine',NULL),(6,2,'Motor 4t/Diesel','4t/Diesel Engine',NULL),(7,2,'Motor 2t/Gasolina','2t/Gasolina Engine',NULL),(8,3,'Monoplaza','Monoplaza',NULL),(9,3,'Biplaza','Biplaza',NULL); /*Table structure for table `tipo` */ DROP TABLE IF EXISTS `tipo`; CREATE TABLE `tipo` ( `id_tipo` int(2) unsigned NOT NULL auto_increment, `tipo_es` varchar(50) NOT NULL default '', `tipo_en` varchar(50) NOT NULL default '', `activado` enum('SI','NO') NOT NULL default 'SI', `des_tipo` varchar(255) default NULL, PRIMARY KEY (`id_tipo`), UNIQUE KEY `tipo_es` (`tipo_es`,`tipo_en`) ) TYPE=MyISAM COMMENT='Tipos de inmueble'; /*Data for the table `tipo` */ insert into `tipo`(`id_tipo`,`tipo_es`,`tipo_en`,`activado`,`des_tipo`) values (1,'BARCOS DE VELA','BOATS DE VELA','SI',NULL),(2,'BARCOS DE MOTOR','BOATS DE MOTOR','SI',NULL),(3,'MOTOS DE AGUA','JETSKY','SI',NULL); /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; Lo que pretendo es coger los datos que faltan de las otras tablas ya que en la tabla artículos tengo hechas referencias (normalización).
No encuentro el problema por ningún sitio así que agradecería un poco de ayuda.
Muchas gracias |