I am writing a little test app which connects to a SQL Server database which has 2 tables in it. Table 1 is a list of data with a non unique key which points to multiple rows in table 2. At the moment what I do is traverse each record in Table 1 and then get the relevant records from Table 2 with a separate query. Table 2 has over 26 million records in it and this process takes a very long time. The data in Table 1 could have just a few hundred records in it or anything up to about 1 million.
Is there a way of speeding up this data access? Perhaps using a table join to get all the data in one query? Or anything else?
Sorry I cannot post the database tables or current code as I am under NDA as it is very sensitive data. The current code is sort of irrelevant here anyway as I am looking for a totally new (and better) way of doing this.
Please note I am using ADO within .NET with C#.
EDIT: I am okay doing the JOIN query but more asking if this will be more efficient with ADO? I know it would be more efficient in general but not sure if ADO can handle this. Also looking for some example C# code to do this. Thanks.