Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

usar o NOT IN ou EXISTS - MySQL 2 aula 1-6.

A questão pede para não usar o EXISTS e sugere usar o "left join, que ainda não aprendemos". No entanto, pode-se usar também o NOT IN?

-- solução conhecida select a.nome from aluno a where not exists (select m.id from matricula m where m.aluno_id = a.id and m.data > now() - interval 45 day );

-- outra solução select * from aluno a where a.id not in (select aluno_id from matricula where data > now() - interval 45 day );

1 resposta
solução!

Bom dia Thiago!

Eu testei a query que você sugeriu, com o not in e deu certo.

select * from aluno a where a.id not in (select aluno_id from matricula where data > now() - interval 45 day );

Para dar o mesmo resultado que essas outras:

Solução conhecida:

select a.nome from aluno a where not exists ( select m.id from matricula m where m.aluno_id = a.id and m.data > (now() - interval 45 day) );

Solução alternativa, com left join:

select a.nome from aluno a left join matricula m on a.id = m.aluno_id and m.data > (now() - interval 45 day);

É só você trocar o * (asterisco) por a.nome:

select a.nome from aluno a where a.id not in (select aluno_id from matricula where data > now() - interval 45 day );

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software