Solved

Need to select two distinct columns in my recordset

Posted on 2012-04-12
6
345 Views
Last Modified: 2012-04-13
I have one table named AttendanceGrid:

Here are an example of the data and column names

Name   Activity   Start          Stop       Month      Notes

Bobby      Tennis    12:00pm   2:00pm   January     None
Timmy     Tennis    12:00pm   2:00pm   February     None
Joyce        Tennis    1:00pm    3:00pm    February     None
Dennis     Tennis    12:00pm   2:00pm   January     None
Sue          Tennis    1:00pm     3:00pm   January     None
Bart         Soccer   12:00pm   2:00pm   January     None

I would like to select Distinct Activity records associated with the Start and Stop Time.  For example if I selected distinct Activity associated with Start and Stop times I should be able to pull up the following:

Tennis   12:00pm  2:00pm
Tennis   1:00pm    3:00pm
Soccer   12:00pm   2:00pm

How can I write an SQL statement to do that?  I am quite novice to SQL code
0
Comment
Question by:al4629740
6 Comments
 
LVL 14

Accepted Solution

by:
nishant joshi earned 167 total points
ID: 37839184
select  Activity,MAX(Start),MAX(Stop) from tbl group by Activity

Open in new window

0
 
LVL 23

Assisted Solution

by:wdosanjos
wdosanjos earned 167 total points
ID: 37839210
Perhaps:
select distinct Activity, Start, Stop
  from AttendanceGrid

Open in new window

0
 

Author Comment

by:al4629740
ID: 37839626
What does the Max in  MAX(Start) mean?
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 14

Expert Comment

by:nishant joshi
ID: 37844062
max which is an aggregate function.
0
 

Author Comment

by:al4629740
ID: 37844975
what does it do?
0
 
LVL 75

Assisted Solution

by:Anthony Perkins
Anthony Perkins earned 166 total points
ID: 37845444
Here is what SQL Server's BOL states about MAX():

Returns the maximum value in the expression.
...
For character columns, MAX finds the highest value in the collating sequence.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

828 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