How to merge different tables with Select [closed]

0

I have 3 tables

Animal - (ID, Description, Code) AnimalRacao - (ID, Animal_id, Racao_id, Quantity) Racao - (ID, Description, Value)

An animal can have several rations.

I would like to make a select that shows me the description of the animal, the description of the rations associated with it, the amount of ration and create a field that shows the Total value that the quantity times the value.

Can anyone help me?

Follow the images of the bank



    
asked by anonymous 22.10.2018 / 22:10

1 answer

1
SELECT animal.descricao, -- Descrição do animal
       racao.descricao,  -- Descrição das rações associadas a ele
       animalracao.quantidade, -- Quantidade da ração 
       animalracao.quantidade * racao.valor as 'valorTotal' -- Campo criado com o valorTotal
FROM animalracao 
INNER JOIN animal 
      ON animal.id = animalracao.id 
INNER JOIN racao ON animalracao.racao_id = racao.id where animal.id = 1 --ID do animal que você deseja.

Animaltable

Animal-rationtable

Table racao

Note : This select for the poodle returns the record with the values: poodle - description of the animal feed for meek animals - feed description 5 - quantity 75 - total value (qtd * ration value)

    
22.10.2018 / 22:48