Solved

Need help with a query

Posted on 2016-08-08
4
53 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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

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.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
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.

920 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

16 Experts available now in Live!

Get 1:1 Help Now