I am trying to create a database that contains users (general) and two more tables, that is: male / female choice. This will be used for dating, more specifically the fact that a girl votes for a boy, a boy for a girl. If their choices are overlapping, it means that they fit together.
I do not know if I approached the topic well, but so far I have built the following code:
USERS: | ID (PRIMARY) | NAME | GENDER | | 1 | Man1 | Male | | 2 | Man2 | Male | | 3 | Woman1 | Female | | 4 | Woman2 | Female | Woman_Result | ID (PRIMARY) | ID_PERSON | ID_CHOOSE | | 1 | 3 | 1 | | 2 | 3 | 2 | | 3 | 4 | 1 | Man_Result | ID (PRIMARY) | ID_PERSON | ID_CHOOSE | | 1 | 1 | 4 | | 2 | 2 | 1 | So the match of those people is only: Man1 and Woman2
SELECT w.*, m.* FROM Man_Result AS m JOIN Woman_Result AS w WHERE w.ID_CHOOSE = m.ID_PERSON AND m.ID_CHOOSE = w.ID_PERSON OUTPUT:
| ID | ID_PERSON | ID_CHOOSE | ID | ID_PERSON | ID_CHOOSE | | 1 | 1 | 4 | 1 | 4 | 1 | So its working, but how i can connect it to my USERS table to get those output:
NAME | NAME Man1 | Woman2 I have combined with something like this, but I don't know completely how to combine it to make it work :)
SELECT USERS.NAME FROM USERS INNER JOIN Woman_Result ON USERS.ID = Woman_Result.ID_PERSON INNER JOIN Man_Result ON USERS.ID = Man_Result.ID_PERSON -- EDIT --
If I wanted to add "ID_CHOOSE2", "ID_CHOOSE3" etc to each user, what kind of query would I have to create for it to be correct? I Tried use "OR":
ON w.ID_CHOOSE OR w.ID_CHOOSE2 = m.ID_PERSON AND m.ID_CHOOSE OR m.ID_CHOOSE2 = w.ID_PERSON And
ON (w.ID_CHOOSE = m.ID_PERSON AND m.ID_CHOOSE = w.ID_PERSON) OR (w.ID_CHOOSE2 = m.ID_PERSON AND m.ID_CHOOSE2 = w.ID_PERSON) But the second example only compares the same columns, and my point is that it compares each to each as in the example with one person