I've been having some trouble with an SQL statement I'm trying to create and I figured that someone here would probably be able to help me out.
I've got two tables: Matches and Users. The Matches table consists of User_id and Partner_id that represents a user and their respective match (partner). Each time a user clicks a button, a new match will be found and a row will be created in the Matches table.
Now, when a user clicks the button to find a match, I need to - randomly - find a user in the Users table that is not the user himself (obviously) and does not already have a relation to the current user in the Matches table. - This is where I get stuck.
How can I pick a user based on the criteria that they do not already have a relation to the currently logged in user, through the Matches table?
All answers are much appreciated. Thank you.
Edit: Having read both SQL - find records from one table which don't exist in another and Sql select row if no row exists in other table (as well as others) only had me more confused afterwards. - I simply didn't quite understand the answers that were given well enough to convert them to what would have been useful in my case.