w3resource

SQL Challenges-1: Unique values

SQL Challenges-1: Exercise-14 with Solution

From the following table, write a SQL query to find the unique marks. Return the unique marks.

Input:

Table: student_test

Structure:

FieldTypeNullKeyDefaultExtra
student_idint(11)YES
marks_achievedint(11)YES

Data:

student_idmarks_achieved
156
274
315
474
589
656
793

Sample Solution:

SQL Code(MySQL):

DROP TABLE IF EXISTS student_test;
CREATE TABLE student_test(student_id int,  marks_achieved int);
INSERT INTO student_test VALUES (1, 56);
INSERT INTO student_test VALUES (2, 74);
INSERT INTO student_test VALUES (3, 15);
INSERT INTO student_test VALUES (4, 74);
INSERT INTO student_test VALUES (5, 89);
INSERT INTO student_test VALUES (6, 56);
INSERT INTO student_test VALUES (7, 93);
SELECT * FROM student_test;
SELECT DISTINCT(marks_achieved) AS  'Unique Marks' FROM student_test;

Sample Output:

Unique Marks|
------------|
          56|
          74|
          15|
          89|
          93|

SQL Code Editor:


Contribute your code and comments through Disqus.

Previous: Find the even or odd values.
Next: Find Student Supporter.



Follow us on Facebook and Twitter for latest update.