1
I am trying to show a table where only the name of the author appears once in which his book is in stock=0, however I am getting the name of all authors in duplicate, even when the author has no stock =0. I have the table writes that has author_idautor and book_idlivro, both are foreign keys in author and book.
select nome from autor,livro where estoque=0;
 Autor
 +----------+--------------+------+-----+---------+-------+
 | Field    | Type         | Null | Key | Default | Extra |
 +----------+--------------+------+-----+---------+-------+
 | idautor  | int(11)      | NO   | PRI | NULL    |       |
 | nome     | varchar(150) | NO   |     | NULL    |       |
 | datanasc | date         | NO   |     | NULL    |       |
 +----------+--------------+------+-----+---------+-------+
 Livro
 +-----------------+--------------+------+-----+---------+-------+
 | Field           | Type         | Null | Key | Default | Extra |
 +-----------------+--------------+------+-----+---------+-------+
 | idlivro         | int(11)      | NO   | PRI | NULL    |       |
 | titulo          | varchar(100) | NO   |     | NULL    |       |
 | preco           | float        | NO   |     | NULL    |       |
 | estoque         | int(11)      | YES  |     | NULL    |       |
 | editora         | varchar(45)  | NO   |     | NULL    |       |
 | genero_idgenero | int(11)      | NO   | MUL | NULL    |       |
 +-----------------+--------------+------+-----+---------+-------+
 Escreve
 +---------------+---------+------+-----+---------+-------+
 | Field         | Type    | Null | Key | Default | Extra |
 +---------------+---------+------+-----+---------+-------+
 | autor_idautor | int(11) | NO   | PRI | NULL    |       |
 | livro_idlivro | int(11) | NO   | PRI | NULL    |       |
 +---------------+---------+------+-----+---------+-------+
can kindly by the structure of the two tables?
– Jasar Orion
If you have two tables (author and book) you must specify some form of link between the records of each table.
– anonimo
@Jasarorion put the two tables using describe same.
– Vitor Gonçalves
@anonimo I have table writes that has author_idautor, book_idlivro. both are foreign keys in the author table and book respectively.
– Vitor Gonçalves
From what you posted above, it doesn’t seem to me that either field is a foreign key. Perhaps in the book table you have the indication of its author or even, in the general case, have another table correlating authors and books (relationship N:N).
– anonimo
after declaring the tables I did the following command, alter table writes add Foreign key (autore_author) Author (author author (author));
– Vitor Gonçalves