N
N
nonvon2021-06-25 19:44:23
MySQL
nonvon, 2021-06-25 19:44:23

How not to take records from the first table if there is one in the second one?

Two tables

`material` (
`id` int(11) NOT NULL,
`created_by` int(11) NOT NULL,
)

`blacklist` (
`id` int(11) NOT NULL,
`user_id` int(11) NOT NULL ,
`created_by` int(11) NOT NULL,
)

I need to take all the rows from the first table if in the second in the user_id field there will be created_by from the first and created_by from the second will be equal to for example 3

How it works - the user is logged in and he does not see some records from the first table if another user is on the black list.

i.e. select * from material
if material.created_by != blacklist.user_id
and blacklist.created_by = 3

something like this (((he got confused already. Please tell me with a request

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BasiC2k, 2021-06-25
@BasiC2k

SELECT Tb1.*, Tb2.*
FROM
(SELECT * FROM material) AS Tb1
LEFT JOIN
(SELECT * FROM blacklist) AS Tb2
ON Tb1.created_by = Tb2.user_id
HAVING Tb2.created_by = 3

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question