Much interface query for many SQL server

Asked

Viewed 1,567 times

3

Hello, I have a question to make a select in the SQL SERVER. I have 3 tables. They are, BOOKS, AUTHOR and LIVRO_AUTOR. To LIVRO_AUTOR has foreign key to the id of BOOKS And AUTHOR. I need to make a select that returns all books with authors born in Brazil (this field is in the author table). I kept thinking about this problem for some time, it seems simple. but so far I have not found how to make it work.

2 answers

3


Jhow has more than one way to solve his problem, one of them would be :

      select titulo from livros inner join livro_autor on livros.id = livro_autor.fk_livro 
      inner join autor on autor.id = livro_autor.fk_autor 
      where autor.pais = 'Brasil'group by livros.id , livros.titulo 

2

Hello, I don’t know the structure of your tables, so I’ll try to help you...

select livros.titulo,
       autor.pais
From livros inner join livro_autor
On livros.objectid = livro_autor.objectidlivro
Inner join autor
On autor.objectid = livro_autor.objectidautor
where autor.pais = 'Brasil'

livros.titulo should be replaced by the name of the column where the title information is in its table books. (Livros.nome_da_coluna)

autor.pais should be replaced by the name of the column where the country information is in the author table. (Autor.nome_da_coluna)

In the Internet, where is objectid you must replace by the name of the column where are the information that relates in your tables, initially in the table books, then in the livro_autor which relates to books. Then the column of the author table which relates to the table livro_autor.

I hope I’ve helped you, in case you got a little confused, enter the names of these columns that I assemble the correct script again.

Let me know if it works.

  • Hello, William. Welcome! When the question you intend to answer does not have enough details to give a satisfactory answer, it is preferable to expect clarification from the author. You can comment to ask for it yourself as soon as you gain a little more reputation. Also, use the formatting tools to separate text code, so that it is easier to distinguish. You can get a sense of how the answer is getting by looking at the preview just below the edit box.

Browser other questions tagged

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