Show related of three tables

0

I have four tables, the first one would be:

The table "articles" this table only has id_articulos, descripcioncorta, archivo, id_estatus.

The table "images" which will contain the id_imagenes and the location of the images, the table.

The table "texts" which contains the text_id and the text as such.

All this I link with a table called "position" in which I keep the id_position, the id_imagenes, the id_textos and the position

I try to make a Query that brings me all the images and all the texts that exist with the id of an article but I duplicate it, here the Query that tries

SELECT localizacion,texto from imagenes,textos WHERE id_imagenes IN 
    (SELECT id_imagenes FROM posicion WHERE id_articulos = 1) AND id_textos IN 
    (SELECT id_textos FROM posicion WHERE id_articulos = 1)
    
asked by Alejandro Guillo Martnez Arreo 22.10.2018 в 20:05
source

1 answer

0

Based on the Query you wrote, this is the most correct way I found to do what you need:

 SELECT i.localicacion,t.texto FROM posicion p 
 INNER JOIN imagenes i ON i.id_imagenes = p.id_imagenes
 INNER JOIN textos t ON t.id_textos = p.id_textos

The position table is responsible for linking your tables, based on their id's I do the corresponding joins to access the information of all your tables.

    
answered by 22.10.2018 / 21:54
source