Solved

Need to select two distinct columns in my recordset

Posted on 2012-04-12
6
350 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Upgrading to SQL Server 2015 Express 2 36
Regarding Disk IO 3 49
add stored proc on publlication 4 20
Better way to filter date  - Query 5 25
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
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 extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

726 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