Solved

Need to select two distinct columns in my recordset

Posted on 2012-04-12
6
334 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
I have a large data set and a SSIS package. How can I load this file in multi threading?
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

929 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

21 Experts available now in Live!

Get 1:1 Help Now