Note that there are some explanatory texts on larger screens.

plurals
  1. POUnknown column in `where` clause
    primarykey
    data
    text
    <p>I am getting the error described in title:</p> <pre><code>Unknown column 'FeedbackType' in 'where clause' </code></pre> <p>But I don't understand why. This is my query:</p> <pre><code>SELECT SQL_CALC_FOUND_ROWS `Appointments`.ID, FeedbackType, FeedbackSubType FROM `UserFeedback` INNER JOIN `Appointments` ON `Appointments`.ID = `UserFeedback`.Appointments_ID INNER JOIN `Reasons` ON `UserFeedback`.FeedbackSubType = `Reasons`.ID WHERE `FeedbackType` = 1 ORDER BY `Appointments`.ID ASC LIMIT 0, 10 </code></pre> <p><code>FeedbackType</code> is a column in the <code>UserFeedback</code> table, casing is correct, checked it several times already.</p> <p>For completeness, this is the table schema:</p> <pre><code>CREATE TABLE IF NOT EXISTS `UserFeedback` ( ID bigint(20) NOT NULL AUTO_INCREMENT, FeedbackType int(4) NOT NULL, FeedbackSubType int(4) NOT NULL, Notes varchar(170) NULL, Appointments_ID bigint(20) NOT NULL, IpTracking_ID bigint(20) NOT NULL, PRIMARY KEY (ID), FOREIGN KEY (Appointments_ID) REFERENCES Appointments(Id), FOREIGN KEY (IpTracking_ID) REFERENCES IpTracking(Id) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; </code></pre> <p>What could be the issue?</p> <p><strong>[Edit]</strong></p> <p>These variants don't work either (because <code>FeedbackType</code> does not contain reserved words/characters and belongs only to the <code>UserFeedback</code> table):</p> <pre><code>... WHERE UserFeedback.FeedbackType = 1 ... WHERE `UserFeedback`.`FeedbackType` = 1 ... WHERE FeedbackType = '1' etc. </code></pre> <p>(and I actually see no reason why they should)</p> <p><strong>[Edit 2]</strong></p> <p>I ran <code>SELECT * FROM UserFeedback</code> to make sure it really contains the column, and I got several rows, all containing the column (well, <code>INSERT</code>s worked without errors).</p> <p>For each of the mentioned variants, I always get the same error, always in the <code>WHERE</code> clause. If I omit the <code>WHERE</code> clause, I get unfiltered results (including the <code>FeedbackType</code> column in those results), so it's really confusing.</p> <p><strong>[Solution]</strong></p> <p>For some reason, replacing the <code>WHERE</code> query with a condition inside <code>INNER JOIN</code> fixed it, as @MarinSagovac <a href="https://stackoverflow.com/a/12877506/1488067">suggested in his second snippet</a>:</p> <pre><code>SELECT SQL_CALC_FOUND_ROWS `Appointments`.ID, FeedbackType, FeedbackSubType FROM `Appointments` INNER JOIN `UserFeedback` ON `Appointments`.ID = `UserFeedback`.Appointments_ID AND `UserFeedback`.FeedbackType = 1 INNER JOIN `Reasons` ON `UserFeedback`.FeedbackSubType = `Reasons`.ID ORDER BY `Appointments`.ID ASC LIMIT 0, 10 </code></pre> <p>Note that there's no <code>WHERE</code> clause now, but the semantics should be the same, right? And it's clear that the column really exists, so the error message is a bit misleading IMHO.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload