max function or alternative to cut down number of rows?
763900Jul 29 2010 — edited Jul 29 2010Hello All,
I have a query that brings back a number of Deals from a table (DEAL). Each deal has one or many Services from a table (SRVC) associated with it. The query is currently joined on where DEAL.DEALID = SRVC.DEALID.
This brings back more rows than I need, I'm not interested in all of the Services per deal, just the one with the highest ID number will do for my purposes.
I do not know how to bring back a single row for each deal ID and discard the excess rows brought about by the multiple services? Can I use a MAX function or something like that?
SELECT
DEAL.DEALID,
SRVC.SRVCID
FROM
DEAL,
SRVC
WHERE
DEAL.DEALID = SRVC.DEALID
AND SRVC.SRVCTYPID IN (6)
I had expected this to be quite simple but I'm really scratching my head over it, really appreciate any help!
Thanks
Jon