Dear all.
Let me explain a simple scenario.
suppose i have two tables tbl_Leads and tbl_Leads_Correspondence.
and i have following data in both table
tbl_Leads
LeadID lName lDate
1 first 2014-11-24 22:22:52.523
2 second 2014-11-25 22:22:52.523
3 third 2014-11-26 22:22:52.523
4 fourth 2014-11-27 22:22:52.523
5 fifth 2014-11-28 22:22:52.523
6 sixth 2014-11-29 22:22:52.523
tbl_Leads_Correspondence
ID LeadID byName Date
1 1 waqas 2014-11-24 22:22:52.523
2 3 waqas 2014-11-26 22:22:52.523
3 4 wilfred 2014-11-27 22:22:52.523
4 5 wilfred 2014-11-28 22:22:52.523
5 6 wilfred 2014-11-29 22:22:52.523
6 6 waqas 2014-11-29 22:22:52.523
7 6 waqas 2014-11-29 22:22:52.523
8 6 waqas 2014-11-29 22:22:52.523
9 6 waqas 2014-11-29 22:22:52.523
10 6 waqas 2014-11-29 22:22:52.523
11 6 waqas 2014-11-29 22:22:52.523
12 1 wilfred 2014-11-29 22:22:52.523
it can be seen that the second table tbl_Leads_Correspondence has leadid as foreign key from the first table.
now my problem is that
i want only those leadID and total count of leadIDs from the table tbl_Leads_Correspondence where byName= wilfred
which are initiated by wilfred.
for example,
LeadID 6 in tbl_Leads_Correspondence has multiple records but i want the leadid 6 only when it was first entered by wilfred. Like the leadID will be returned only in case of wilfred as wilfred was the first person who entered the record in database.
similarly the leadID from tbl_Leads_Correspondence will only be returned when the byName 'waqas' will be passed to the query as parameter.
i hope i make my self clear..
any help or sample query will be greatly appreciated..
Regards: