Query sql SELECT

0

What command select shows me only those comments from a single user?

For example: I have a Post table where you store the comments of each user (user_1, user_2, user_3), but would like to show only user_1 comments.

Comments table is called Post :

ID_POST
ID_USER (chave estrangeira para a tabela Users, campo ID_USER)
mensagem
data

Users table is called Users :

ID_USER
username
avatar
    
asked by anonymous 13.02.2018 / 13:33

2 answers

0

According to the information provided:

SELECT comentario FROM comentario WHERE usuario = "usuario_1"

By deducing that the name of the column that stores the comments is comentario , that the name of your table is comentario , and that the column that stores the users is usuario .

EDIT - Due to new information later reported

SELECT mensagem
FROM Post
INNER JOIN Users ON Users.ID_USER = Post.ID_USER
WHERE Users.username = "usuario_1"
    
13.02.2018 / 13:47
0

From what I understood from your question, this would be:

/*Buscando pelo nome do usuário*/
SELECT * FROM Post
WHERE ID_USER = (
    SELECT ID_USER FROM Users
    WHERE Login LIKE '%Texto_da_Busca_Pelo_Login_do_Usuario%'
)

/*Buscando pelo id do usuário*/
SELECT * FROM Post
WHERE ID_USER = 'ID_Digitado_Pelo_Usuario'
    
15.02.2018 / 17:32