I have three tables and I need to find the very first date and the very last(recent) date of an event users has joined as a host and a guest. In other words, the returned data should look like the following:
(please note that it's the very first and the very last(recent) date of all events a user has attended)
+----+-----+---------+----------------------+-----------------------+-----------------------+-----------------------+
| id |name | Event | First date as a host | Recent date as a host | First date as a guest | Recentdate as a guest |
+----+-----+---------+----------------------+-----------------------+-----------------------+-----------------------+
| 1 | Teo | Dance | 2018-01-01 | 2017-01-01 | 2016-02-01 | 2017-09-09 |
| 2 | Jac | Karaoke | 2018-03-02 | 2018-01-01 | 2016-07-07 | 2017-01-06 |
| 3 | Lay | Boxing | 2017-09-09 | 2018-07-07 | 2017-01-01 | 2018-02-02 |
+----+-----+---------+----------------------+-----------------------+-----------------------+-----------------------+
Tables
Users
id
name
Event
id
name
starts_at
Event_Users
id
user_id
event_id
role
I tried to follow an instruction here[https://www.periscopedata.com/blog/4-ways-to-join-only-the-first-row-in-sql]... but when it comes to writing a query that retrieves 4 different first rows(min/max), i always end up with a super messy query that doesn't even work...
What would be the easiest solution for this kind of tricky requirement?
Thanks