SQL Max Group By Query Help
Posted
by Hcabnettek
on Stack Overflow
See other posts from Stack Overflow
or by Hcabnettek
Published on 2010-05-28T22:49:45Z
Indexed on
2010/05/28
22:52 UTC
Read the original article
Hit count: 539
Hi All, I have a quick question. How do I select the two values I need in one query? Currently I'm doing this, which works fine, but it's obviously running two queries when one should do the trick. I tried MAX(columnA) and GROUP BY ColumnB, but that returns multiple row. I only want one row returned.
DECLARE @biID bigint
, @dtThreshold DateTime
SELECT @biID = MAX(biID)
FROM tbPricingCalculationCount WITH (NOLOCK)
SELECT @dtThreshold = dtDateTime
FROM tbPricingCalculationCount WITH (NOLOCK)
WHERE biID = @biID
I would like both those variables to be set correctly in one query. How can I do that?
Thanks, ~ck
© Stack Overflow or respective owner