Solved

Return only one value based on columns in SQL

Posted on 2009-07-15
2
231 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 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