I have a table that could have thousands (millions maybe?) of records. It is basically an audit trail table that stores special log entries. It's called "Logs".
There is also a related table called "LogsExtended" which stores zero or many additional records for each entry in the Logs table.
There is a foreign key relationship setup, complete with deletion cascade etc.
I am doing a SELECT on the Logs table to select all records that occurred in a specific time range, say "the last 30 days".
However I want to somehow simultaneously select the related foreign records in the LogsExtended table. With the intention that the results of this query will be filled into a DataSet that has the proper DataRelation setup.
I have tried using various JOIN clauses but these all tend to result in the wrong behaviour -- where entries from Logs get repeated for each related record there is in the LogsExtended table.
I really want to avoid the obvious fallback solution which is to query the Logs table first, then, for each result, run an additional query to get the LogsExtended records as well. That strikes me as pretty wasteful and could result in thousands of queries being run.
I think I'm making a bit of a mountain of a molehill out of this but I just can't figure it out.
Thanks.