Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm new to MySQL. I'm having trouble in joining two tables:

SELECT e.resourceName
 FROM resources_in_room r
 JOIN resource e ON r.resourceId=e.resourceId WHERE r.roomId=2;

Table resources in room:

CREATE TABLE  ``resources_in_room` (
  `id` bigint(20) NOT NULL auto_increment,
  `Quantity` int(11) default NULL,
  `resourseId` int(11) default NULL,
  `roomId` int(11) default NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `resourseId` (`resourseId`,`roomId`),
  KEY `FK36360B9B821B4697` (`roomId`),
  KEY `FK36360B9BC0C935AD` (`resourseId`),
    FOREIGN KEY (`resourseId`) REFERENCES `resource` (`ResourceId`),
  CONSTRAINT `FK36360B9B821B4697`
    FOREIGN KEY (`roomId`) REFERENCES `room` (`RoomId`)

Table resource:

CREATE TABLE  `resource` (
  `ResourceId` int(11) NOT NULL auto_increment,
  `Description` varchar(255) default NULL,
  `Quantity` int(11) default NULL,
  `ResourceName` varchar(255) default NULL,
  PRIMARY KEY  (`ResourceId`)
share|improve this question
im getting syntax error "Unknown column 'r.resourceId' in 'on clause'" – Okky Aug 10 '12 at 6:26
Frankly if you can, I would fix the misspelling of resourceid now. This is bound to cause lots of wasted time debugging in the future. – HLGEM Aug 10 '12 at 18:45
up vote 4 down vote accepted

its resourseId in your table definition and you are using resourceId in query.

This will work

SELECT e.resourceName FROM resources_in_room r join resource e on r.resourseId = e.resourceId where r.roomId=2;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.