I'm trying to make a query and add the values of two tables to the result so I can bring the inflationary I need
tables matches
and blocked
are related to users
using the id's
The query I am trying to make is the following:
SELECT u.*, m.*
FROM users u, matches m
WHERE NOT EXISTS (
SELECT idblock
FROM blocked b
WHERE b.idBlock = u.id AND b.idBlocked = 9) AND u.id <> 9
and the result brings it as I need but it repeats many times, I tried to do it with a where exists
but it did not work for me
this is the relationship that the tables have
What I try to bring in my query is all the information of id
and the fields idMatch
and% idMatched
as long as accepted = 0
in the table of matches
but as long as the id
User% does not exist in idBlocked
RELATIONSHIP BETWEEN TABLES
the table of users
is the primary table for consequent
in the table matches idMatch y idMatched
have a FK
to id
of the table users
as shown in the image
and in the blocked idBlock y idBlocked
table have FK
a id
of users
Both tables have a ratio of 1 to many
I repeat the intention of my query again:
I want to bring all the user information to show it on the screen but I want to know if you already have a match
to show a button, but in case there is no match show another button but I also want to know if the user id the blocked table has not been entered
ex. if user 1 blocks user 3 will not appear on screen but all others if
Relationship of if's between tables
@ A.Cedano as you mention, the match and blocked tables are relations between users, I really do not know how to explain what I want to do.
but in my head my intention is to take all the records of the users table after making a comparison in the match table, that is, if in the match table the idMatch user is = 9 and idMatched = 3 in the view will show a button, otherwise another button will be displayed
then I want to make another comparison where one user has not blocked another is to say if idBlock = 3 and idBlocked = 9, the user with id 3 will not be shown on screen for user 9.
and so at the end say "ok, the result brought all users of the users table but id 9 has a match with id 7, then I will show this button but id 3 blocking id 9, then I will not show this user "
But all that I want to do in a single query so you can show all the results on screen