I have three tables: users, types, and expenses. The expense table has the fields id_expenses, expenses, date, value, and location; the type table has the type of expense has the fields type_id and type (the type table refers to the type of expense: transactional and in kind). The users table has the id, user, and email fields. So I want to bring the user's expenses with a type and a date range. For example: I have the expense of a shoe bought through the internet, so it is transactional and the expense TV bought in kind (money). If I just want a user's in-kind expense list in a time frame?
SELECT despesas.id_despesa, despesas.despesa, despesas.valor_despesa, despesas.data_despesa, despesas.local_despesa, tipos.tipo
FROM despesas
inner join users
inner join tipos on despesas.fk_id_user = users.id
WHERE tipos.tipo = '{$this->request->data['Relatorio']['tipo']}' and despesas.data_despesa between '{$this->request->data['Relatorio']['dataInicial']}' and '{$this->request->data['Relatorio']['dataFinal']}'
ORDER BY despesas.data_despesa asc"';
The query is bringing all records, either transactional or in kind.
Note that the application is in php as you see it.