1
I have five tables, cis with the fields id, id_referencia, tipoci and numci, the others are cigeral, ciintercambio, cihoraextra and cicompensacao.
When I create one of the cis give a insert in the table referring to the type of ci and
one insert on the table cis referencing the id of ci country maid id_referencia and in the field tipoci state the type and logic creates the number of the ci in the field numci, because although they are of different types all must follow the same order of numbering.
The problem is that I cannot create a query that searches all cis of all tables because the tables have some equal fields but some have more fields than others, for example:
cigeral owns the fields: id, tipoci, id_user, destino, assunto, dataci and discriminacao.
ciintercambio owns the fields: id, tipoci, id_user, destino, assunto, dataci, intercambista, dataintercambio and turno
Wanted a query return to me all fields of the 4 tables based on id_referÊncia table cis. fields that did not exist in the other tables were shown as null.
When I perform the query below it returns only the 3 cis exchange with their respective cis numbers, the other 8, which are of different types appear with all the data as null.
SELECT cis.numci, ciintercambio.* from cis LEFT JOIN ciintercambio on cis.id_referencia = ciintercambio.id AND cis.tipoci = 2
Hello! It would help if you gave a small example of the tables, their content and expected result on
SELECT.– Dherik
Describe there that
cis.tipocicorresponds to which table (ciintercambio,cigeral,cihoraextraandcicompensacao). This smells like another case of UNION with LEFT JOIN.– Marcelo Shiniti Uchimura