How do I Inner Join with these tables?

Asked

Viewed 265 times

-5

How would the SELECT query in Mysql from the Inf_musicas table? inserir a descrição da imagem aqui

  • What you want to return?

  • Possible duplicate of How to relate several tables?

  • yes! I want a select

  • 1

    You could explain better what you want? On that other question of yours you explained a little better by saying that you wanted to exchange the foreign key values of inf_musicas by the values of the other tables. Is that what you want to do here? If so, what is the specific difficulty that is not elucidated in your other question? If not, then what is it you need?

1 answer

2

Suppose these are the tables:

Table of Members

CREATE TABLE Integrantes(
   ID INT AUTO_INCREMENT PRIMARY KEY,
   Nome NVARCHAR(50) NOT NULL,
);

Band Table

CREATE TABLE Bandas(
   ID INT AUTO_INCREMENT PRIMARY KEY,
   Banda NVARCHAR(50) NOT NULL,
   IntegranteID INT NOT NULL,

   CONSTRAINT FK_IntegrantesDaBanda
   FOREIGN KEY (IntegranteID)
   REFERENCES Integrantes.ID
);

Table of Record Companies

CREATE TABLE Gravadoras(
   ID INT AUTO_INCREMENT PRIMARY KEY,
   Gravadora NVARCHAR(50) NOT NULL,
);

Table of Songs

CREATE TABLE Musicas(
   ID INT AUTO_INCREMENT PRIMARY KEY,
   Musica NVARCHAR(50) NOT NULL,
   BandaID INT NOT NULL,
   GravadoraID INT NOT NULL,

   CONSTRAINT FK_MusicaDaBanda
   FOREIGN KEY (BandaID)
   REFERENCES Bandas.ID,

  CONSTRAINT FK_MusicaDaGravadora
   FOREIGN KEY (GravadoraID)
   REFERENCES Gravadoras.ID
);

Query

SELECT M.Musica, B.Banda, G.Gravadora FROM Musicas AS M
INNER JOIN Bandas AS B ON M.BandaID = B.ID
INNER JOIN Gravadoras AS G ON M.GravadoraID = G.ID

I hope I’ve helped!

  • more how do I associate with members? and I’m weeding and pasting this giving error!

  • There is a band Foreign key that associates the members to the band... Copy and paste will not help, Oce used different data in its creation. What do you need?

Browser other questions tagged

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