I’m trying to run a MYSQL query where I need the same ‘piece’ of information from the source table twice in the destination…
Let me explain:
2 Tables: “Events” and “Archived Events“.
The “Archived Events” is a ‘link’ – bridging current open events to past (closed) events.
This table only contains id’s to the Event_ID in the Events table.
What I want to do is get the Event Title for each combination in the archive table.
EG:
-----------------------------------
| ARCHIVE TABLE |
|PK|ClosedEventID |CurrentEventID |
|1 | 5 | 3 |
|2 | 2 | 3 |
-----------------------------------
-----------------------------------------
| EVENTS TABLE |
|Event_ID | Event_Title | ............. |
| 1 | Party 1 | ............. |
| 2 | Party 2 | ............. |
| 3 | Wedding 1 | ............. |
| 4 | Funeral 1 | ............. |
| 5 | Pancake | ............. |
----------------------------------------
I’m guessing it’s going to be a join or a union or something; my SQL is fair, but my head is spinning trying to work this out.
So what I would like done is that for each ‘pair’ in the archive events table would look like this once the query was run (so that I can deal with it in PHP…):
-----------------------------------
| ARCHIVE TABLE |
|PK|ClosedEventID |CurrentEventID |
|1 | Pancake | Wedding 1 |
|2 | Party 2 | Wedding 1 |
-----------------------------------
Thank you for your help in advance! 🙂
This is fairly simple: