how to make queries of 3 different tables in mysql in different capos

0

Excuse me, I'm doing a query where I need data from 3 different tables and the query is executed but in the column of table 1 and table two the data is repeated and those in the 3rd column if shown as they should, that I have to fix in my office to show me everything right?

    
asked by Giancarlo Andre Lopez Silva 27.06.2018 в 17:42
source

1 answer

0

how are you? I commented, what I see is that you are doing a FullJoin

From what I see you want to do an INNER JOIN (Relating the tables)

If this is the case first look for a column that you can relate in the tables and then have the queries.

SELECT t1.campo1, t2.campo2, t3.campo3
FROM tabla1 t1
inner JOIN tabla2 t2 ON t1.columnaCompartidax = t2.columnaCompartidat2 
inner JOIN tabla3 t1 ON t1.columnaCompartidax = t3.columnaCompartidat3 

Also, if you need to go deeper into these topics, I recommend you

link

In case you can return an unordered table:

SELECT 'Titulo' as 'Key', titulos.titulo 'Value'
FROM titulos
where clausula
------------
UNION ALL
SELECT 'Autores' as 'Key', autores.nombre as 'Value'
FROM autores
where clausula
------------
UNION ALL
SELECT 'Genero' as 'Key', generos.nombre as 'Value'
FROM titulos
where clausula

El resultado seria 

    Key || value
_____________________________
  Titulo|| Ejemplo de titulo
  Titulo|| Otro Titulo
 Autores|| Autor1
 Genero || Policial

Greetings.

    
answered by 27.06.2018 / 18:30
source