Select one table base on value of another table [message #330983] |
Wed, 02 July 2008 00:47 |
tmlaio
Messages: 6 Registered: September 2006
|
Junior Member |
|
|
I have a user table and a transaction table.
User table have the following sample data:
user_id start_date end_date
------- ---------- --------
1 1-Apr-2007 31-Mar-2008
1 1-Jun-2008 31-Dec-2008
2 1-Jan-2008 31-Dec-2008
...
Transaction table have the following sample data:
tran_id tran_date
------- ---------
100 1-Mar-2008
101 4-Mar-2008
102 15-Apr-2008
103 12-May-2008
104 6-Jun-2008
...
User table control which user can access to transactions of which period. The same user will not have overlapped periods.
The problem is user can enquiry on transactions within a specifed date range. We have to list all the relevant transactions but exclude those not accessible by the user.
For example, user with id 1, enquiry transactions between 1-Feb-2008 and 30-Jun-2008, we should only return transaction ids 100, 101 and 104, excluding 102 and 103.
How should I construct the sql, please help. Thanks in advance.
|
|
|
|
|
|
|