A better solution is to use a left join it is more efficient than using the IN clause
Select
t1.*
from
Table1 t1
left join Table2 t2 on t1.date_field = t2.date_field and t1.number_dialed = t2.number_dialed
where
t2.date_field is null
The left join means return all records in Table1 even if there is no matching record in Table2 in which case nulls are returned for the Table2 columns. So if we specify null as the criteria in the where clause we get only records in Table1 that are unmatched, meaning they don't exist in Table2.
hollystyles
Veteran Poster
1,182 posts since Feb 2005
Reputation Points: 262
Solved Threads: 68
Sorry I don't get what you want. First you say:
The common filed in both tables are dates and number dialed. Please help me to get the calls records registered in Table 1 but are not shown in table 2
Then you say:it gives me only records of telephone numbers that are not mentioned in Table2 at all. but there are calls to telephone numbers that exist in both table
To me these are mutualy exclusive.
Given the sample data you have posted, please post what you want to see in the result set. Then perhaps I might be able to figure out what you're after.
hollystyles
Veteran Poster
1,182 posts since Feb 2005
Reputation Points: 262
Solved Threads: 68
Ok then you need to join *all* the fields.
Select
t1.*
from
Table1 t1
left join Table2 t2 on t1.[Date] = t2.[Date]
and t1.[Time] = t2.[Time]
and t1.[Duration] = t2.[Duration]
and t1.[number dialed] = t2.[number dialed]
and t1.Cost = t2.Cost
where
t2.[Date] is null
Note:
The [] around column names are because I think some of those are reserved words in SQL and that is how you escape them. I don't know if they are your actual column names.
hollystyles
Veteran Poster
1,182 posts since Feb 2005
Reputation Points: 262
Solved Threads: 68