I have an event
table
+----------+------------+
| event_id | event_name |
+----------+------------+
| 1 | event1 |
| 2 | event2 |
| 3 | event3 |
| 4 | event4 |
+----------+------------+
And an event_performer
table
+--------------------+----------+--------------+
| event_performer_id | event_id | performer_id |
+--------------------+----------+--------------+
| 1 | 1 | 1 |
| 2 | 1 | 2 |
| 3 | 2 | 1 |
| 4 | 2 | 2 |
| 5 | 3 | 3 |
| 6 | 3 | 4 |
| 7 | 4 | 3 |
| 8 | 4 | 4 |
+--------------------+----------+--------------+
I want to get all the events with performer ids 1 and 2, so I run the following query:
select event.* from event
join event_performer
on event.event_id = event_performer.event_id
and performer_id in (1,2)
order by event_name
When I do that, I obviously get duplicate events (two for event_id 1 and two for event_id 2). What's the most efficient way in MySQL remove the duplicates so that I get each event record once?
One idea is to use select distinct event.*
How efficient is that for a large number of fields and records?
Note that the example tables are oversimplified. Each table has MANY more fields and MANY more records.