john010117 Posted March 1, 2008 Share Posted March 1, 2008 I need help with this query: SELECT polls. * , poll_options. * FROM polls, poll_options LEFT JOIN poll_votes ON polls.poll_id = poll_votes.poll_id WHERE polls.poll_id =1 AND poll_options.poll_id = polls.poll_d Here's my database structure for the three tables: -- -- Table structure for table `polls` -- CREATE TABLE `polls` ( `poll_id` mediumint(5) NOT NULL auto_increment, `poll_question` varchar(200) NOT NULL, `poll_start` int(11) NOT NULL, `poll_end` int(11) NOT NULL, `poll_type` tinyint(1) NOT NULL default '1', PRIMARY KEY (`poll_id`), KEY `poll_start` (`poll_start`,`poll_end`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; -- -------------------------------------------------------- -- -- Table structure for table `poll_options` -- CREATE TABLE `poll_options` ( `option_id` mediumint(5) NOT NULL, `poll_id` mediumint(5) NOT NULL, `option_name` varchar(200) NOT NULL, KEY `option_id` (`option_id`,`poll_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; -- -------------------------------------------------------- -- -- Table structure for table `poll_votes` -- CREATE TABLE `poll_votes` ( `vote_id` int(11) NOT NULL auto_increment, `poll_id` mediumint(5) NOT NULL, `option_id` mediumint(5) NOT NULL, `vote_user` int(11) NOT NULL, KEY `vote_id` (`vote_id`,`poll_id`,`option_id`,`vote_user`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; MySQL returns with an error: #1054 - Unknown column 'polls.poll_id' in 'on clause' Any help will be appreciated. Link to comment https://forums.phpfreaks.com/topic/93905-query-help/ Share on other sites More sharing options...
fenway Posted March 2, 2008 Share Posted March 2, 2008 Try this: SELECT polls. * , poll_options. * FROM ( polls, poll_options ) LEFT JOIN poll_votes ON polls.poll_id = poll_votes.poll_id WHERE polls.poll_id =1 AND poll_options.poll_id = polls.poll_d You recently upgraded to v5, right? Link to comment https://forums.phpfreaks.com/topic/93905-query-help/#findComment-481358 Share on other sites More sharing options...
john010117 Posted March 2, 2008 Author Share Posted March 2, 2008 Ok, I think I got it. Thanks. Link to comment https://forums.phpfreaks.com/topic/93905-query-help/#findComment-481367 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.