2
I have two tables:
formulario_campo ( cod_campo, descricao, cod_formulario )
Filled with the following values
- input_nome, Nome, 1
- input_sexo, Sexo, 1
The second table:
— formulario_valor(cod_campo,valor,cd_oportunidade)
In this table are the linked records of the fields and their respective values, as follows:
- input_name, Fagner, 2
- input_sex, M, 2
To bring the filled values from the table formulário_valor i make a main select in table formulario_campo and then I make a left outer join on the table formulario_valor to bring value:
SELECT
a.`cod_campo`,
a.`descricao`,
b.valor,
b.`cod_formulario`,
b.`cod_oportunidade`
FROM
formulario_campo a
LEFT OUTER JOIN formulario_valor b
ON (
a.`cod_campo` = b.`cod_campo`
AND a.`cod_formulario` = b.`cod_formulario`
)
WHERE b.cod_oportunidade = 145
ORDER BY a.`ordem`
That select brings me back:
Doubt: adding new fields in the formula_field table, for example now I added a new field called: input_birth date, logically this field has no values recorded in the table formulario_valor, the problem is being this point, the select what I am doing above should not return me all the field values I have recorded in the table "formulary_field" and the record input_birth date came with the value of NULL?
Attempts I made:
- FULL OUTER JOIN
- LEFT OUTER JOIN
- RIGHT OUTER JOIN
- UNION
But all this I could not bring the new fields that I add with null value...

Try to put this instruction
WHERE b.cod_oportunidade = 145inside the ON of the LEFT JOIN.and b.cod_oportunidade = 145. Must solve.– Thiesen
Whoa, thanks for the help, I tried to do it the same way, but it wasn’t...
– Roni Sommerfeld
There is no dynamic pro solution you want. You will have to adjust on the arm whenever you have a new field. If I understand your problem.
– DH.
Hello @Darkhyudra thank you again, but the term "there is no solution" is incorrect, a solution exists yes, in our developer life everything is possible until the moment we think, but I believe something very silly is missing in this select, in summary I have a table B that has the registered values of table A, at a given moment I am taking all the records of table A and displaying the values of table B, but when I added a new record in table A that does not exist in table B the select above should return me the column Table value B as null, right?
– Roni Sommerfeld
One question: in select you have the new field?
– user4701