I have a stored procedure which looks at both a master table and a detail table. Part of the code is below.
This should display one record for each master record where data tblDetail.UsedBy = 'mike'. However, when I run this I get a record for each detail record.
For example, If record "123" in tblMaster has 5 detail records in tblDetail where tblDetail.UsedBy = 'mike' then I get 5 returned records after the stored proc runs. I only want to get 1 returned record in this example.
How can I modify this so that I can use the detail table criteria in my WHERE clause but limit the returned values to only those from the master table?
Thanks.
--
Mike
This should display one record for each master record where data tblDetail.UsedBy = 'mike'. However, when I run this I get a record for each detail record.
For example, If record "123" in tblMaster has 5 detail records in tblDetail where tblDetail.UsedBy = 'mike' then I get 5 returned records after the stored proc runs. I only want to get 1 returned record in this example.
How can I modify this so that I can use the detail table criteria in my WHERE clause but limit the returned values to only those from the master table?
Code:
SELECT dbo.tblMaster.FlitchNum
FROM dbo.tblMaster INNER JOIN
dbo.tblDetail ON dbo.tblMaster.FlitchNum = dbo.tblDetail.FlitchNum
WHERE tblDetail.UsedBy = 'mike'
ORDER BY tblDetail.DateUsed
GO
Thanks.
--
Mike