Solved

Need help with a query

Posted on 2016-08-08
4
44 Views
Last Modified: 2016-08-08
Hi Experts,

This is my query. I have attached the output I am getting.  How can I modify the query to get the userID and name only once.

SELECT C.ID, C.StudentID,c.ClassID, c.InstructorID ,c.TimeID ,(rtrim(U.UserFirstName)) + '' +
ltrim(rtrim(U.UserLastName)) as UserName,
ltrim(rtrim(U.AttendenceDay))  as AttendenceDay FROM CLASSSETUP as C
LEFT OUTER JOIN  USERDETAILS As U on C.StudentID=U.UserID
Where  C.ClassID =15 order by UserName
Query.txt
0
Comment
Question by:RadhaKrishnaKiJaya
4 Comments
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 41747457
what do you do with other values like ID, clsid, InsID, ... which are not unique for a single user?
0
 
LVL 5

Expert Comment

by:Manuel Flores
ID: 41747463
using group by clause... however you should get rid of ID and TimeID... is this possible?
0
 
LVL 65

Accepted Solution

by:
Jim Horn earned 500 total points
ID: 41747465
You'll have to define exactly how you wish the query results to appear, as it looks like for each repeated userID it is returning different ID values and other columns, so the query appears to be working as designed.

For example, user Eulisis_MiddleEu, do you want to see ID values 201, 160, 193, or none at all?

If you only want to see StudentID and UserName..
SELECT DISTINCT 
   C.StudentID, 
   rtrim(U.UserFirstName)) + '' + ltrim(rtrim(U.UserLastName)) as UserName
FROM CLASSSETUP as C
   LEFT OUTER JOIN  USERDETAILS As U on C.StudentID=U.UserID
WHERE  C.ClassID =15 
ORDER BY U.UserLastName, U.UserFirstName

Open in new window

0
 

Author Closing Comment

by:RadhaKrishnaKiJaya
ID: 41747497
Thank you.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

747 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

9 Experts available now in Live!

Get 1:1 Help Now