running32
asked on
getting multiple results in query
I created a select query in access. The problem is that if I query on two dates its returns 2 records for each hour when I should only return one. I'm guess I have an incorrect joint but I'm just not sure where? Thank you
SELECT DISTINCT qelMemberperhourbydaterang e.hour, qelMemberperhourbydaterang e.Expr1, qselGuestCountbyHourbyRang e.CountOfl ngpassesus ed, qelMemberperhourbydaterang e.CountOfl ngmemberid , Nz([countoflngPassesused], 0)+Nz([Cou ntOflngmem berid],0) AS Expr2
FROM qelMemberperhourbydaterang e right JOIN qselGuestCountbyHourbyRang e ON qelMemberperhourbydaterang e.hour=qse lGuestCoun tbyHourbyR ange.hour
ORDER BY qelMemberperhourbydaterang e.hour, qelMemberperhourbydaterang e.Expr1;
SELECT DISTINCT qelMemberperhourbydaterang
FROM qelMemberperhourbydaterang
ORDER BY qelMemberperhourbydaterang
Remember that distinct looks at ALL the fields in the result to identify duplicates.
ASKER
I guess I need to join two existing queries together on Date and Time. How can I join the two queries below and not get cross joins? Thanks
Query 1
SELECT Format([dtmdate],"mm/dd/yy yy") AS Expr1, Count(tblGuestPass.lngpass esused) AS CountOflngpassesused, DatePart("h",[dtmdate]) AS [hour]
FROM tblGuestPass
GROUP BY Format([dtmdate],"mm/dd/yy yy"), DatePart("h",[dtmdate]), Format([dtmdate],"mm/dd/yy yy")
HAVING (((Format([dtmdate],"mm/dd /yyyy")) Between [Start Date] And [End Date]))
ORDER BY Format([dtmdate],"mm/dd/yy yy"), DatePart("h",[dtmdate]);
Query 2
SELECT Format([dtmcheckin],"mm/dd /yyyy") AS Expr1, Count(tblcheckin.lngmember id) AS CountOflngmemberid, DatePart("h",[dtmcheckin]) AS [hour], tblcheckin.lngtype
FROM tblcheckin
GROUP BY Format([dtmcheckin],"mm/dd /yyyy"), DatePart("h",[dtmcheckin]) , Format([dtmcheckin],"mm/dd /yyyy"), tblcheckin.lngtype
HAVING (((Format([dtmcheckin],"mm /dd/yyyy") ) Between [Start Date] And [End Date]) AND ((tblcheckin.lngtype)=1))
ORDER BY Format([dtmcheckin],"mm/dd /yyyy"), DatePart("h",[dtmcheckin]) ;
Query 1
SELECT Format([dtmdate],"mm/dd/yy
FROM tblGuestPass
GROUP BY Format([dtmdate],"mm/dd/yy
HAVING (((Format([dtmdate],"mm/dd
ORDER BY Format([dtmdate],"mm/dd/yy
Query 2
SELECT Format([dtmcheckin],"mm/dd
FROM tblcheckin
GROUP BY Format([dtmcheckin],"mm/dd
HAVING (((Format([dtmcheckin],"mm
ORDER BY Format([dtmcheckin],"mm/dd
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Nope this does not work, it states Syntax error near from. Thanks
ASKER
thanks
you got it to work I assume?