Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Distinct values in SQL Query

Tags:

People also ask

How do I show distinct values in SQL?

The SQL SELECT DISTINCT Statement The SELECT DISTINCT statement is used to return only distinct (different) values. Inside a table, a column often contains many duplicate values; and sometimes you only want to list the different (distinct) values.

How do I find distinct values?

In Excel, there are several ways to filter for unique values—or remove duplicate values: To filter for unique values, click Data > Sort & Filter > Advanced. To remove duplicate values, click Data > Data Tools > Remove Duplicates.

How can I get distinct values of all columns in SQL?

To get unique or distinct values of a column in MySQL Table, use the following SQL Query. SELECT DISTINCT(column_name) FROM your_table_name; You can select distinct values for one or more columns.


I have a problem in my SQL Query

i want to select DISTINCT StudentGroups(SG) but the query gives me some repetations

here is my Query

SELECT      DISTINCT(SG.SGID), en.EnrollmentID, CR.Name AS Course, INS.Name as Instructor,
                S.Session, SG.StartTime, SG.EndTime, EN.CreateDate

    FROM        StudentGroups SG inner JOIN Enrollments EN ON SG.SGID = EN.SGID
                JOIN Courses CR ON SG.CourseID = CR.CourseID
                JOIN Class CL ON SG.ClassID = CL.ClassID
                JOIN Instructors INS ON SG.InstructorID = INS.InstructorID
                JOIN Sessions S ON SG.SessionID = S.SessionID

    WHERE       EN.SGID NOT IN ( SELECT SGID FROM Enrollments
                            WHERE StudentID = 45

UPDATED

This query gives me following data

enter image description here

but i don't want repeated SGID