Take the 2-minute tour ×
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. It's 100% free, no registration required.

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`),
  CONSTRAINT `FK36360B9BC0C935AD` 
    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
    
Hello Sreekesh, you should describe what your problem actually is. Syntax error? (In this case please indicate the exact error.) Not the data you're expecting? (In this case, please provide sample data.) Performs too slow? (In this case, please add the explain plan and indexes you have.) –  Mat Aug 10 '12 at 6:05
    
im getting syntax error "Unknown column 'r.resourceId' in 'on clause'" –  Sreekesh Okky Aug 10 '12 at 6:26
1  
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
add comment

1 Answer 1

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
add comment

Your Answer

 
discard

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.