Inner Join does not work - Error 1054

Asked

Viewed 52 times

-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
;
  • Returns an error?

  • But the select is there friend :(

  • The error returned is in the title, 1054

  • Try this: select message.mnsg, message.RM, student.name names them, student.course to courses, student.rm from message Inner Student on student.rm=message.RM order by id asc;

  • Ops, as I was not in the same format, I ended up not seeing, it was bad, I will delete my comment.

  • I’m getting a lot of negative votes, which I did wrong?

  • When things are too basic or asked to do the code, usually people don’t like it and negatively. In your case I believe it was lack of attention to solve the problem, stay more attentive to the structure of the comic

  • I get it, thank you

  • 1

    I don’t know if that’s the case, but there’s a chat option on Stack, I believe it serves that purpose too.

Show 4 more comments

2 answers

1

You are seeking student.course in student, but in creating the student table there is no course column...

Join the course table through the class.

as soon as I get home I edit the answer with the code for you.

  • Thank you so much Luis! You helped me again!

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, being that the course is in the class table.

Browser other questions tagged

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