I am trying to fetch only the last record (last sale) from each client and I am not succeeding. I've tried it in many ways, but nothing .. Just returns all sales from the date. Follow my query. Thanks for the help.
use banco
select m.cli_forn,c.nome,c.telefone,c.fax,m.num_nf,max(convert(date,m.dt_mov))as Data,m.valor_mov,m.cod_vendedor
from tb_movimentos m inner join tb_cliente c on(c.cod_cli=m.cli_forn)
where m.cod_vendedor = '178' and c.cod_cli !='5000' and status_clifor = 'C'and m.dt_mov >='2015-01-01'
group by m.cli_forn,c.nome,c.telefone,c.fax,m.num_nf,m.valor_mov,m.cod_vendedor