Do not list duplicate data

Asked

Viewed 46 times

1

I have two tables, videos and exercicios, where I would like the data that is in the two not to be listed, that is, if the foreign key is in the other table, the data should not be shown in the query to avoid being inserted again.

The tables:

videos(
  id_video,
  titulo_video,
  src_video,
  descricao_exercicio,
  id_professor_video,
  id_categoria_video,
  data_upload
)

exercicios(
  id_exercicio,
  id_treino_exercicio,
  id_aluno_exercicio,
  dia_exercicio
)

I tried to do like the query down but it didn’t work, he keeps showing the videos who have already been registered:

SELECT
  exercicios.*,
  videos.*
FROM (
  exercicios INNER JOIN videos
    ON exercicios.id_treino_exercicio = videos.id_video
)
WHERE 
  id_professor_video = 1
  AND id_categoria_video = 1
  AND dia_exercicio != 1
  • Take a look at Outer Join, solve your problem?

  • or <not exists>

  • Without knowing the structure of your tables, the data that is in it and an example of desired result based on these data is impossible to help you.

1 answer

-1

this code worked the way I wanted, I think Join n was working because n had no null field, even so thank you all for your attention.

SELECT * FROM videos v WHERE v.id_video NOT IN (SELECT id_treino_exercicio FROM exercicios) AND id_professor_video = 1 AND id_categoria_video = 1 

Browser other questions tagged

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