W
WP
I am trying to write a query to find a record that has the
max date, but also meets several other criteria. It's
easy to find the max date that satisfies the criteria..I
use the query below for that:
' Works but unable to show serialnum due to group by
SELECT ModelID,max
(dateentered),machinename,coatingname,sizename
FROM tblmaindesign
WHERE
modelid=23 AND typeid=4 AND machinename="W2" and
coatingname="Chrome" AND sizename="STD"
GROUP BY
modelid, machinename,coatingname,sizename ;
However, if I want to show something like serialnum (I
Need to show it of course) that is unique for each record
I have a problem because of the GROUP BY clause in the
above query. I have come up with something that works but
it repeats the criteria in it so there must be a better
way of doing this. Here's how I have the query now:
SELECT ModelID,serialnum,
dateentered,machinename,coatingname,sizename
FROM tblmaindesign as M
WHERE
modelid=23 AND typeid=4 AND machinename="W2" and
coatingname="Chrome" AND sizename="STD" AND dateentered=
(select max(dateentered) from tblmaindesign as s where
s.modelid=M.modelid and typeid=4 and machinename="W2" and
coatingname="Chrome" and sizename="STD") ;
Any pointers on the best way to get the max date along
side something like a unique serialnum would be greatly
appreciated.
Thank You
max date, but also meets several other criteria. It's
easy to find the max date that satisfies the criteria..I
use the query below for that:
' Works but unable to show serialnum due to group by
SELECT ModelID,max
(dateentered),machinename,coatingname,sizename
FROM tblmaindesign
WHERE
modelid=23 AND typeid=4 AND machinename="W2" and
coatingname="Chrome" AND sizename="STD"
GROUP BY
modelid, machinename,coatingname,sizename ;
However, if I want to show something like serialnum (I
Need to show it of course) that is unique for each record
I have a problem because of the GROUP BY clause in the
above query. I have come up with something that works but
it repeats the criteria in it so there must be a better
way of doing this. Here's how I have the query now:
SELECT ModelID,serialnum,
dateentered,machinename,coatingname,sizename
FROM tblmaindesign as M
WHERE
modelid=23 AND typeid=4 AND machinename="W2" and
coatingname="Chrome" AND sizename="STD" AND dateentered=
(select max(dateentered) from tblmaindesign as s where
s.modelid=M.modelid and typeid=4 and machinename="W2" and
coatingname="Chrome" and sizename="STD") ;
Any pointers on the best way to get the max date along
side something like a unique serialnum would be greatly
appreciated.
Thank You