Jump to content

Query help


john010117

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.