1

我的查询看起来像

SELECT а.*, m.username, m.picture, m.picture_active
FROM questions_answer AS а 
INNER JOIN members AS m ON а.poster_id=m.member_id
INNER JOIN questions AS q ON q.question_id=a.question_id
ORDER BY a.postdate DESC

我收到错误:

Unknown column 'a.question_id' in 'on clause'

我不知道这是怎么回事,请帮我解决这个问题。

questions

CREATE TABLE IF NOT EXISTS `questions` (
  `question_id` int(9) unsigned NOT NULL AUTO_INCREMENT,
  `member_id` int(9) unsigned NOT NULL DEFAULT '0',
  `question` text NOT NULL,
  `postdate` int(10) unsigned NOT NULL DEFAULT '0',
  `active` tinyint(1) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`question_id`),
  KEY `member_id` (`member_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

并且questions_answer

CREATE TABLE IF NOT EXISTS `questions_answer` (
  `answer_id` bigint(12) unsigned NOT NULL AUTO_INCREMENT,
  `question_id` int(9) unsigned NOT NULL,
  `poster_id` int(9) unsigned NOT NULL,
  `body` text NOT NULL,
  `postdate` int(9) unsigned NOT NULL,
  PRIMARY KEY (`answer_id`),
  KEY `question_id` (`question_id`),
  KEY `poster_id` (`poster_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
4

5 回答 5

0

您的表格questions_answer可能没有该列question_id

于 2013-09-15T16:08:32.880 回答
0

看来您没有列 a.question_id

检查该表的结构。

于 2013-09-15T16:10:51.667 回答
0

question_id表中没有调用任何列questions_answer

于 2013-09-15T16:12:37.440 回答
0

有趣的是,如果我使用这段代码,它可以工作:

SELECT qa.*
FROM questions_answer qa
INNER JOIN questions q ON qa.question_id = q.question_id
ORDER BY qa.postdate DESC

SQL小提琴

因此,要将其应用于您的查询:

SELECT qa.*, m.username, m.picture, m.picture_active
FROM questions_answer qa
INNER JOIN questions q ON qa.question_id = q.question_id
INNER JOIN members m ON qa.poster_id = m.member_id
ORDER BY qa.postdate DESC
于 2013-09-15T16:31:03.573 回答
0

您的questions_answer表别名a有一些问题。很可能不是那封信a

FROM questions_answer AS а 

我在玩它,发现一个错误,Unknown table 'аa': 如你所见,它可能是一个特殊字符。在网上进行了简短的搜索,得到了字母Eth

alias用字符替换了,a查询工作正常。

SELECT a.*, m.username, m.picture, m.picture_active
FROM questions_answer AS a
INNER JOIN members AS m ON a.poster_id=m.member_id
INNER JOIN questions AS q ON q.question_id=a.question_id
ORDER BY a.postdate DESC

请参见此处的示例 只需将您的查询复制粘贴到那里并尝试运行,它会因为alias字符问题而抱怨。您甚至可以从您的行中复制别名并a用它替换所有 s,它也可以。

于 2013-09-15T18:02:39.593 回答