Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 30th, 2006, 07:50 AM
Registered User
 
Join Date: Dec 2006
Location: , , United Kingdom.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Query Problem

I am extracting data from an access DB using vb6. I am trying to extract the last 5 transactions for every account a customer has. I can extract every transaction for every account a user has but need to cut it down. I am having to run two queries just now as transactions are held in two different tables i.e. current year and archived transactions. I have to run it on the archived one as some customers havent made 5 transactions in the one year for all their accounts. Can I combine them and extract the last 5 or do I have to keep them seperate.

The queries I have are -
(Current Transactions)

INSERT INTO `Transactions` (credit_union_id, customer_id, account_id, transaction_detail, `timestamp`, amount) SELECT Account.credit_union_id, Account.customer_id, Account.account_id, Trantype_ID.tranname, Membertrans.Trandate, Membertrans.Tranvalue1 FROM Trantype_ID, Membertrans, Account WHERE Trantype_ID.trantype = Membertrans.Trantype AND Membertrans.Memberno = Account.customer_id AND Membertrans.Account = Account.account_id

(Archived Transations)

INSERT INTO Transactions(credit_union_id, customer_id, account_id, transaction_detail, `timestamp`, amount) SELECT Account.credit_union_id, Account.customer_id, Account.account_id, Trantype_ID.tranname, Memberalltrans.Trandate, Memberalltrans.Tranvalue1 FROM Memberalltrans, Account, Trantype_ID WHERE Memberalltrans.Account = Account.account_id AND Memberalltrans.Memberno = Account.customer_id AND Memberalltrans.Trantype = Trantype_ID.trantype

Would appreciate some help in reducing the transactions to 5.
Transactions are timestamped.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Query Problem. rupen Access 3 April 27th, 2007 07:43 AM
query problem purnendu2311 Other Programming Languages 2 December 1st, 2006 02:53 PM
problem with query harpua Classic ASP Databases 1 January 24th, 2005 12:36 PM
Problem in query leo_vinay Classic ASP Databases 5 January 21st, 2005 06:32 AM
query problem mateenmohd SQL Server 2000 7 September 9th, 2003 11:58 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.