Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return single result for each unique record ID

Status
Not open for further replies.

Moss100

Technical User
Aug 10, 2004
579
0
16
GB
Hello I need to return the first result for each Prop_ID in a query.

The query below returns all records (i.e. a number of records for each ID)

Code:
SELECT mqry_tbl_Property.Prop_ID, mqry_tbl_Property.Prop_Address_Sort, mqry_tbl_Filestore.FileStore_Date_Added, mqry_tbl_Filestore.FileStore_Target_Path, mqry_tbl_Filestore.FileStore_TblSup_ID_Link
FROM mqry_tbl_Property LEFT JOIN mqry_tbl_Filestore ON mqry_tbl_Property.Prop_ID = mqry_tbl_Filestore.FileStore_Property_ID_Link
GROUP BY mqry_tbl_Property.Prop_ID, mqry_tbl_Property.Prop_Address_Sort, mqry_tbl_Filestore.FileStore_Date_Added, mqry_tbl_Filestore.FileStore_Target_Path, mqry_tbl_Filestore.FileStore_TblSup_ID_Link
HAVING (((mqry_tbl_Filestore.FileStore_TblSup_ID_Link)=26))
ORDER BY mqry_tbl_Property.Prop_ID, mqry_tbl_Filestore.FileStore_Date_Added DESC;

I have tried a few efforts, but seem to just end up with a single record as opposed to a single record for each ID.

Many thanks Mark
 
QryFirstDatePerProperty
Code:
SELECT 
 FileStore_Property_ID_Link,  
 Min(FileStore_Date_Added) as FirstDateAdded, 
FROM 
 mqry_tbl_Filestore 
GROUP BY 
 FileStore_Property_ID_Link

You can then innerjoin to your query by date and ID. Now this can be done by subqueries or selfjoins in one step. See here.


But building two queries is a lot easier if you have not done this before.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top