1
Hello, I need to do a search in mysql in which I use several Internet joins, and because it is many relationships for many, some of the fields relate to one more field of the other table, follows an example where it will be easier to understand
SELECT livros.id_livro, livros.nome, livros.caminho, categorias.nome as categoria FROM livros INNER JOIN categorizados ON categorizados.id_livro = livros.id_livro INNER JOIN categorias ON categorizados.id_categoria = categorias.id_categoria WHERE categorias.nome LIKE 'Terror' AND categorias.nome LIKE 'Suspense'
Here I highlight the following excerpt: WHERE categorias.nome LIKE 'Terror' AND categorias.nome LIKE 'Suspense'
And it is about him that the doubt is related, in one of my registered books, I have one that has two categories in it registered, one with the name 'Terror' and the other with the name 'Suspense'
But I can not filter this book with this request, I believe there is some way to make this request, but I do not know how yet, I would like you to help me, thank you!
Edit1: The search after the WHERE are in different records, one record has the name field as 'Terror' and the other record has the name field as 'Suspense'
If I understood you should not use OR in place of AND since, as far as I understand, a field cannot have both the values 'Terror' and 'Suspense'. It may be that if you want to select those that have two records in the table categories you can use the usual GROUP BY with COUNT and the clause HAVING COUNT(id_category) > 1.
– anonimo
These are different records, the two tables are related, and I have two records, one with the field name as 'Terror' and another with the field name as 'Suspense'
– Renan