Import description from another table

Asked

Viewed 18 times

0

Hello guys I have the following code:

SELECT COUNT(*) AS categorias_total, v_lctos_despesa.id_categorias
FROM 'v_lctos_despesa'
INNER JOIN categorias ON (v_lctos_despesa.id_categorias = categorias.id_tipo)
GROUP BY v_lctos_despesa.id_categorias

however the result of it is not correct, I would like him to bring the description of the category and not the id:

categoria1 = 10
categoria2 = 15

he’s bringing:

1 = 10
2 = 15

1 answer

0

Wouldn’t be the case just you change the return field?

SELECT COUNT(*) AS categorias_total, v_lctos_despesa.desc_categorias --valida o nome do campo
FROM 'v_lctos_despesa'
INNER JOIN categorias ON (v_lctos_despesa.id_categorias = categorias.id_tipo)
GROUP BY v_lctos_despesa.desc_categorias

Obs: Notice that by doing this, you need to also change the field of group by, which must be the same as that brought in select.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.