SQL Challenges-1: Unique values
From the following table, write a SQL query to find the unique marks. Return the unique marks.
Input:
Table: student_test
Structure:
Field | Type | Null | Key | Default | Extra |
---|---|---|---|---|---|
student_id | int(11) | YES | |||
marks_achieved | int(11) | YES |
Data:
student_id | marks_achieved |
---|---|
1 | 56 |
2 | 74 |
3 | 15 |
4 | 74 |
5 | 89 |
6 | 56 |
7 | 93 |
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.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics