I have a table that contains assignment_id, student_id, assignment_name and assignment_date. I have to write a SQL query to get list of students who submitted 2 assignments on same date. I also need assignment_name and assignment_date in output. I am stuck with which query can I write to get this data. Any help would be highly appreciated
Asked
Active
Viewed 3,097 times
1
-
2(1) You should show your attempted query. (2) You should tag with the database you are using. – Gordon Linoff Jul 23 '18 at 00:58
-
Hi Gordon, I am using Oracle SQL. I am very new to SQL queries and completely stuck with where to start from – user10119684 Jul 23 '18 at 00:59
-
Hi Gordon, I am using Oracle SQL. I am very new to SQL queries and completely stuck with where to start from – user10119684 Jul 23 '18 at 00:59
-
Hint : `Group by student_id,training_date` + `Having` – Kaushik Nayak Jul 23 '18 at 03:49
2 Answers
0
You can try something like this
In MYSQL Query
SELECT student_id, training_date, GROUP_CONCAT(assignment_name)
FROM
table_name
GROUP BY student_id, training_date HAVING COUNT(*) = 2
"Is there any function in oracle similar to group_concat in mysql?" might help you to replace GROUP_CONCAT in oracle SQL

Manish Singh
- 934
- 1
- 12
- 27

Hardik Nuwal
- 73
- 8
-
Hardik, thank you so much for your help. But GROUP_CONCAT is giving me an error. I think it doesnt work in Oracle – user10119684 Jul 23 '18 at 05:10
-
https://stackoverflow.com/questions/16771086/is-there-any-function-in-oracle-similar-to-group-concat-in-mysql Hope this helps. – Hardik Nuwal Jul 23 '18 at 05:32
0
You can use exists
:
select t.*
from table t
where exists (select 1
from table t1
where t1.student_id = t.student_id and
t1.training_date = t.training_date and
t1.assignment_id <> t.assignment_id
);

Yogesh Sharma
- 49,870
- 5
- 26
- 52