Dude, your tables aren’t optimized and you’re going to have problems down the road with names, references, etc., like using CPF as a user id in the shopping table. The most appropriate would be to use an auto-increment for a sequential ID and then use it.
Think that when using CPF you may have problems with searches (easy to misspell, you will have to deal with invalid Cpf cases, etc.).
I also think it’s not cool you allow the table purchased with the 2 fields set in null, so what would you store in a case of double nulls?
But since you are a beginner, then this is normal. Do not worry, here is a link for you to learn some basic things relating to cross data between tables and that will make all the difference.
Meanwhile, this is the code you need:
select cursos.nome, usuarios.nome
from cursos, usuarios, comprados
where comprados.usuarios_id = usuarios.cpf
and comprados.cursos_id = cursos.id;
Search on
join
. I would add that storing CPF as a whole is not a good idea. As much as it looks like a number, it is actually a text made up of numeric characters. To verify this, just think that011 111 111 11
is different from the value11 111 111 11
. When represented as integer, the left zero is discarded.– Woss
There are a number of links answering your question in this post: https://answall.com/questions/267808/70
– Bacco