Solved

Return only one value based on columns in SQL

Posted on 2009-07-15
2
203 Views
Last Modified: 2012-05-07
I'm trying to only return the STOREID and POLL_TIME in a query based on the @StartDate. Each STOREID has multiple entries for each date so I'm getting something like this currently:

StoreID     POLL_TIME
1               5:57
1               6:23
1               7:23
2               1:42
2               4:23


I only want to return this:

StoreID     POLL_TIME
1               7:23
2               4:23

Any help here?
SELECT 

	SUMMARY.STOREID, 

	SUMMARY.POLL_TIME

FROM 

	SUMMARY 

WHERE 

	SUMMARY.Current_Batch_Date = @StartDate

	

ORDER BY 

	STOREID

Open in new window

0
Comment
Question by:mattkovo
2 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 500 total points
ID: 24864115
SELECT
      SUMMARY.STOREID,
      MAX(SUMMARY.POLL_TIME) Poll_Time
FROM
      SUMMARY
WHERE
      SUMMARY.Current_Batch_Date = @StartDate
GROUP BY    STOREID  
ORDER BY
      STOREID
0
 

Author Closing Comment

by:mattkovo
ID: 31603997
Genius!  Thanks!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now