I have two tables in a database (in Mysql) both tables have different fields, one of which has a field called cuenta
and costo
, and the other one a field called numero
:
Tabla uno
cuenta | costo
Y,
Tabla dos
numero
From table two I must perform a concatenation to obtain a field called referencia
select concat('1','-45',numero,'-12')referencia from dos
I compare the field cuenta
and referencia
of each of the tables and if the fields are the same then print the field costo
.
The query is as follows:
select u.costo
from dos d LEFT JOIN uno u ON concat('1','-45',d.numero,'-12')=u.cuenta
So in my query you should show me 3 columns; the concatenated fields, the number field and finally the query that shows the equality and what I want is for the fields to remain empty or with 0 in those fields where there are no equalities.