MySQL Forums
Forum List  »  MySQL Query Browser

Where clause
Posted by: artur correia
Date: January 15, 2012 12:24PM

Hi
Been struggling with this for a while:

Have two tables:

Table 1 - has a description of files and identifies file owner, referencing fileid, description, owner, etc ...

Table 2 - has the flow of every file, referencing fileid, date, description, etc...

I'm trying to get a query so the output is file description from Table 1 and the <b>last</b> record inserted in Table 2 for each file on Table 1

I came up with this:
select Table1.idconta idconta, Table1.descricao descricao, max(Table2.idmovimento) id, Table2.descricao descrip from Table1 left join Table2 using (idconta) group by Table1.idconta order by Table2.idmovimento;

Problem is that this doesn't output the last record (table2) for each file (table1), but rather the first record.

I've tried a couple of variations, but at most I can get a similar query that returns all results on table2 for every table1 file.

Much appreciated
Artur

Options: ReplyQuote


Subject
Written By
Posted
Where clause
January 15, 2012 12:24PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.