It would be best if you could define the 2 tables in terms of their rows and join criteria - a create table statement for each would be best - because otherwise its difficult to help you since you do not detail what you tried and what the error message was either :-(
You are right, select distinct can be used to retrieve distince (unique) valued rows but you have to be careful with those rows that occur in both tables. Be sure to always specifiy the table you are revering to:
Select distinc m.Field1, d.Field2
From MasterTable m
INNER JOIN DetailTable d
on m.key = d.key
WHERE Criteria
How about a statment like the above where selected field is specified with a specific table m or d for
Master and
DetailTable. Does this work? If not what is the specific table design, query statement and error message?
As for the
group by
this is also useful for selecting distinct rows but it is usually only used when you want to count things, like dublicate rows or determine min() or max() values. A typical usage is like the statement above but with a
group by clause
and you have to use extra care to
select only values that are also present in the group by clause (min() or max(), or sum()) can be selected without having to be in the group by clause per se). So how about a statment like this:
Select m.Field1, d.Field2, count(*)
From MasterTable m
INNER JOIN DetailTable d
on m.key = d.key
WHERE Criteria
group by m.Field1, d.Field2
Does this work? If not what is the specific table design, query statement and error message?