MS Access Query building for VB6
I am using vb6 and I have a table in access database which contains following fields --
1) account_no
2) account_type
3) trans_date
4) sequence_no
5) deposit
6) withdrawl
7) balance
At the time of first transaction of every account_no of a particular account_type, the sequence_no will be 1. Then after every transaction, the sequence_no field is incremented with 1 for each account_no of a particular account_type and balance field is also changed accordingly. There may be same sequence_no against many transactions of different account_no.
Now, I want to build a report of the last balance of every account_no of a particular account_type i.e. where the sequence_no is maximun for every account_no.
Can anybody help me building the query for the above purpose ? ?
Re: MS Access Query building for VB6
You can use Access Function MAX for this purpose. For example:
SELECT Max(Sequence_No) FROM MyTable WHERE Account_No = 9999
Here is a link to help you out a bit more on the Max function.
http://www.databasedev.co.uk/access_max_function.html
Re: MS Access Query building for VB6
Thanx for your reply.
I know the MAX function but I need the value of BALANCE field for every account number where the sequence no. is maximum.
something like this --
"Select account_no, balance
From Mydb.table1
Where sequence_no = max(sequence_no)
Group by account_no"