Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need help with a query

Posted on 2016-08-08
4
Medium Priority
?
83 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
[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
4 Comments
 
LVL 70

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 66

Accepted Solution

by:
Jim Horn earned 2000 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how the fundamental information of how to create a table.

661 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