Inner Join Does Not Work - Error 1054

-2

Could someone explain to me why this query does not work?

select mensagem.mnsg, aluno.nome as nomea, aluno.curso as cursoa 
from mensagem 
inner join aluno on aluno.rm=mensagem.RM 
order by id asc;


-- Table aluno

CREATE TABLE 'aluno' (
'RM' INT(11) NOT NULL,
'Turma_ID' INT(11) NOT NULL DEFAULT '0',
'Foto' TINYBLOB NULL,
'Nome' VARCHAR(50) NULL DEFAULT NULL,
'Email' VARCHAR(50) NULL DEFAULT NULL,
'Senha' VARCHAR(50) NULL DEFAULT NULL,
PRIMARY KEY ('RM'),
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB
;

-- Table mensagem

CREATE TABLE 'mensagem' (
'ID' INT(11) NOT NULL AUTO_INCREMENT,
'RM' INT(11) NOT NULL,
'mnsg' TEXT NULL,
'RM_PROF' INT(11) NULL DEFAULT NULL,
'Turma_ID' INT(11) NULL DEFAULT NULL,
PRIMARY KEY ('ID')
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB
AUTO_INCREMENT=3
;

-- Table turma

CREATE TABLE 'turma' (
'Turma_ID' INT(11) NOT NULL DEFAULT '0',
'curso' VARCHAR(50) NULL DEFAULT NULL,
'ano' INT(11) NULL DEFAULT NULL,
'QNT_ALUNO' INT(11) NULL DEFAULT NULL,
PRIMARY KEY ('Turma_ID')
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB
;
    
asked by anonymous 25.09.2018 / 21:45

2 answers

1
Select mensagem.mnsg, 
      aluno.nome as nomea, 
      turma.curso as cursoa
From mensagem 
Inner join aluno on 
     aluno.rm=mensagem.RM
Inner join turma on
     turma.Turma_ID = mensagem.Turma_ID
Order by id asc;

You were selecting the course in the student, and the course is in the class table.

    
25.09.2018 / 22:05
1

You are looking for student.current in student, but in the creation of the student table there is no course column ...

Join the course table through the class_ID that will work.

Once I get home I edit the answer with the code for you.

    
25.09.2018 / 22:01