1

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

Image of the data

user10119684
  • 29
  • 1
  • 2

2 Answers2

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, 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