I have five tables, cis with the fields id
, id_referencia
, tipoci
and numci
, the others are cigeral
, ciintercambio
, cihoraextra
cicompensacao
.
When I create one of the cis I give insert
in the table referring to the type of ci
e
a insert
in the cis
table referencing the id
of the ci
created in the id_referencia
field and in the tipoci
field I indicate the type and the logic creates the ci
number in the numci
field, because although they are of different types all must follow the same order of numbering.
The problem is that I can not create a query that fetches all cis from all tables because the tables have some equal fields but some have more fields than others, for example:
cigeral
has the fields: id
, tipoci
, id_user
, destino
, assunto
, dataci
and discriminacao
.
ciintercambio
has the fields: id
, tipoci
, id_user
, destino
, assunto
, dataci
, intercambista
, dataintercambio
I wanted a query to return all fields of the 4 tables based on turno
of the id_referÊncia
table. the fields that did not exist in the other tables were shown as cis
.
When I perform the query below it returns me only the 3 null
of exchange with their respective cis numbers, the other 8, which are of different types appear with all data as cis
.
SELECT cis.numci, ciintercambio.* from cis LEFT JOIN ciintercambio on cis.id_referencia = ciintercambio.id AND cis.tipoci = 2