Jump to content

Query help


john010117
 Share

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • 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.