Skip to content
Advertisement

MYSQL Select different records from same table

I am working on small school database and I need some help with selecting students that are only booked on different days in week 1 and week 2.

My table structure is like below:

I would like to get all the children that meet the following criteria:

  • ONLY booked in week two (This is ChildId 2 and I can get this from the following query)

I also need

  • all children in week two whose days are different then week one. That will be ChildID 3 as he is booked on Monday and Tuesday on Week 1 and on Monday on week 2.

I am unable to get the children whose days are different in both the weeks:

Thank you

Advertisement

Answer

You can do it with aggregation and the conditions in the HAVING clause:

See the demo.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement