ms access - SQL to Get Only One Record for Each "item" Based on different column -
i have worked week researching question , learning different sql techniques. trying display results in listbox in microsoft access. have columns sqlidofloggers, jobnumber, datedeployed, datereturned, ahulocation, accesspoint
, 2 comboboxes cbologgertype , cboorderby
filter these results (i did workaround cboorderby
using vba, that's why not in posted sql).
what want pull 1 record each distinct sqlidoflogger
. determine 1 record among several each sqlidoflogger
want order them datereturn
-eds , pick latest don't want show records datereturn
null, i.e. they're still out on job
this sql have brings correct information, shows more 1 record each logger:
select (select top 1 tblloggers.loggerid tblloggers tblloggers.id = tbluse.idoflogger) sqlidoflogger, (select top 1 tblprojectlist.jobnumber tblprojectlist where( tblprojectlist.id = tbluse.idofproject)) expr1, tbluse.datedeployed, tbluse.datereturned, tbluse.ahulocation, tbluse.accesspoint tbluse ( (iif([forms]![frmbytype].[cbologgertype]<>'(all)', ((select top 1 tblloggers.loggertype tblloggers tblloggers.id = tbluse.idoflogger order id)=[forms]![frmbytype].[cbologgertype]), '*')<>false ) , ( (tbluse.datereturned) in (select max(tbluse.datereturned) tbluse group tbluse.idoflogger)) ) group tbluse.datedeployed, tbluse.datereturned, tbluse.ahulocation, tbluse.accesspoint, tbluse.idofproject, tbluse.idoflogger order 1, tbluse.ahulocation;
i tried clean code best possible. know it's not ideal, kept adding bits , pieces went along , "works". post i've tried last little bit of equation none of them work (obviously haha). don't know best course of action (group by
, join
, exists
, etc.), i'm open suggestions.
Comments
Post a Comment