Query sql SELECT

Asked

Viewed 119 times

0

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

For example: I have a table Post where it stores the comments of each user (usuario_1, usuario_2, usuario_3), but would like to show only the comments of the user.

Table of comments is called Post:

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

Table of users is called Users:

ID_USER
username
avatar

2 answers

0

From what I understand of your question, that 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'

0


According to the information provided:

SELECT comentario FROM comentario WHERE usuario = "usuario_1"

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

EDIT - Due to new data later informed

SELECT mensagem
FROM Post
INNER JOIN Users ON Users.ID_USER = Post.ID_USER
WHERE Users.username = "usuario_1"
  • I think I should be more specific kkkk, I have a users table and another post table, the post table has column = id_post, column = foreign id_user key which is the id_user of the users table, has message column, column = data_post, now the users table has column = id_user, column = username, column = avatar

  • SHOW FULL COLUMNS FROM fieldName (if it is Mysql). I believe that you cannot have a SELECT exclusive to a field.

  • 1

    Caraka bro really that was what I was looking for flw hug..

Browser other questions tagged

You are not signed in. Login or sign up in order to post.