Unknown column 'topics.id' in 'field list'

SELECT topics.id topicId, [...]

topics.id DOES exist.

Recommended Answers

All 7 Replies

Hi,

topics.id stands for tableName.columnName, if this is not the case and you have a column name with a dot, then do:

SELECT `topics.id` FROM `topics`;

This will select the column with the dot. If it was a table name, instead it would be:

SELECT `topics`.`id` FROM `topics`;

Ref: http://dev.mysql.com/doc/refman/5.7/en/identifiers.html

Yes, I know. Table topics and within column id exists. This error occurs.

Ok, can you show the full query and the create table statement? Run: show create table topics;

SHOW CREATE TABLE topics

+--------+-----------------------------------------------+
| Table  | Create Table                                  |
+--------+-----------------------------------------------+
| topics | CREATE TABLE `topics` ( `id` int(9) NOT NULL  |
|        | AUTO_INCREMENT, `name` varchar(24)            |
|        | CHARACTER SET utf8 NOT NULL, `closed`         |
|        | int(1) NOT NULL, `postCount` int(9) NOT NULL, |
|        | PRIMARY KEY (`id`), UNIQUE KEY `id` (`id`),   |
|        | KEY `id_2` (`id`)) ENGINE=MyISAM              |
|        | AUTO_INCREMENT=2 DEFAULT CHARSET=latin1       |
+--------+-----------------------------------------------+

Good, can you show also the query cited in your first post?

SELECT topics.id topicId,
      topics.name topicName,
      topics.closed topicClosed,
      forums.lastTopicId forumLastTopicId,
      forums.topicCount forumTopicCount,
      forums.description forumDescription
FROM forums INNER JOIN members ON forums.lastPoster = members.id

The query isn't working at all, so I tried finding if query is incorrect, but before that I need to make the query work, to figure out why it's not working, to figure out how to fix it, so I can get result, which doesn't bring the result, it brings false.

Ok, it happens because the topics table is not listed it the FROM statement, add it as a JOIN, it should fix this issue.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.