1
I have a table with foreign key fields, and would like to return in a select
the value of the item for the key.
For example, I have the following table formed with the query:
SELECT cod_produto,
MQ1FK,
MQ2FK,
MQ3FK,
MQ4FK,
MQ5FK
FROM engenharia_processo
INNER JOIN engenharia_produto
ON cod_produto = codigo;
cod_produto MQ1FK MQ2FK MQ3FK MQ4FK MQ5FK
0101500063500 18 5 null null null
0101500083500 1 3 4 null null
In another table I have the data:
MQPK | Valor
1 2
3 5
4 3
5 9
18 7
I would like to perform a query that returns the table with the Value field instead of the key, type:
cod_produto MQ1FK MQ2FK MQ3FK MQ4FK MQ5FK
0101500063500 7 9 null null null
0101500083500 2 5 3 null null
I tried to use:
select valor from engenharia_maquina where MQPK = (select MQ1FK from engenharia_processo);
But as the return has more than one line not of the right.
http://dev.mysql.com/doc/refman/5.1/en/group-by-functions.html#function_group-Concat
– Motta
You can make a Join Inner in your select
– KhaosDoctor