I need some help creating a query for my mySQL database. I have recently started using JOIN and IN to select rows from my database, so I apologize for sounding like a noob.
I am not looking for an answer (although one would be nice!) but advice on where I should start with my query would be greatly appreciated. Please do not just post a link to the PHP website or to a tutorial.
In my database, users are "linked", the order is NOT important.
Table Name: UserLinks
link_ID User_1 User_2
1 10982* 34982
2 82738 16643
3 10982* 99822
4 78256 10982*
The user that I am focusing on here is user 10982
1) The first part of this query that I would like to create find the ID of the users that this user (10982) is linked to. These users are user 34982, 99822, and 78256. I imagine it is something as simple as SELECT * FROM UserLinks WHERE User_1 OR User_2 = 10982, my issue here is, how do I obtain the values - given that I cannot simply choose a row to return (I considered using an if statement... if the value of User_1 is 10982, then choose User_2. This however, seems redundant.
With this list of Users ID's, I would like to run the second part of the query, to find which Event_ID's correspond to this list of users (the ID's of the users are now UserEv_ID):
Table Name: EventUserTags
ETag_ID UserEv_ID Event_ID
1 34982* 289
2 82738 231
3 99822* 990
4 78256* 486
2) The second part of this query will use the list generated from the first query (of user ID's) to generate a list of Event_ID's. I know that you can use the IN statement and just dump this list in to the query as an array, but that means making the results of the first part of the query into an array. This again, seems redundant. I would like to know how to properly select these Event_ID's using the User ID's... I think that the JOIN Query will work, but I need some advice on how to use this.
The values of Event_ID's obtained here are 289, 990, and 486. In last part of this query I need to use this list of Event_ID's generated from the last query to match up with the data of another table, my Events table.
Table Name: Events
Event_ID Event_Order
182 8728342
289 3478792*
990 1876623*
486 9617789**
3) Lastly, I need to use the Event_ID's obtained from the last query to obtain their corresponding Even_Order. Again, I know this can be done with the IN statement (using an array) but this will not be efficient at all.
The purpose of this query is to start with a single User's ID, and find the Event_Order of every user this user is linked to.
Any help is really appreciated