neo926 Posted August 9, 2007 Share Posted August 9, 2007 SELECT DISTINCT(DATE_FORMAT(submitted,'%M')) AS mymonth , DATE_FORMAT(submitted,'%Y') AS myyear , title FROM secondcitysaint WHERE myyear = '2007' ORDER BY submitted DESC #1054 - Unknown column 'myyear' in 'where clause' I created this temporary column called 'myyear' with the AS function above, and I want to pull data based on a certain year that's listed in the 'myyear' column, but MySQL tells me the column isn't there. Is there a way I can fix this? Link to comment https://forums.phpfreaks.com/topic/64010-mysql-where-error/ Share on other sites More sharing options...
neo926 Posted August 9, 2007 Author Share Posted August 9, 2007 Sorry, I'm using SQL 4.1 Link to comment https://forums.phpfreaks.com/topic/64010-mysql-where-error/#findComment-319073 Share on other sites More sharing options...
teng84 Posted August 9, 2007 Share Posted August 9, 2007 can you paste the exact error Link to comment https://forums.phpfreaks.com/topic/64010-mysql-where-error/#findComment-319075 Share on other sites More sharing options...
neo926 Posted August 9, 2007 Author Share Posted August 9, 2007 I did, the second code box. Here's the full message: Error SQL query: Documentation SELECT DISTINCT ( DATE_FORMAT( submitted, '%M' ) ) AS mymonth, DATE_FORMAT( submitted, '%Y' ) AS myyear, title FROM secondcitysaint WHERE myyear = '2007' ORDER BY submitted DESC LIMIT 0 , 30 MySQL said: Documentation #1054 - Unknown column 'myyear' in 'where clause' Link to comment https://forums.phpfreaks.com/topic/64010-mysql-where-error/#findComment-319078 Share on other sites More sharing options...
teng84 Posted August 9, 2007 Share Posted August 9, 2007 try to remove the where clause first and see what happen Link to comment https://forums.phpfreaks.com/topic/64010-mysql-where-error/#findComment-319081 Share on other sites More sharing options...
neo926 Posted August 9, 2007 Author Share Posted August 9, 2007 It works fine without the WHERE clause, it's just when I add it in Link to comment https://forums.phpfreaks.com/topic/64010-mysql-where-error/#findComment-319085 Share on other sites More sharing options...
teng84 Posted August 9, 2007 Share Posted August 9, 2007 i guess you have to fallow what ure DB wants your code should work but maybe all you can do is not to use that alias and rely on the real tbl Link to comment https://forums.phpfreaks.com/topic/64010-mysql-where-error/#findComment-319093 Share on other sites More sharing options...
neo926 Posted August 9, 2007 Author Share Posted August 9, 2007 Well, I'd be more than happy to just pull the year from my submitted column, but I don't know how to do that, since it's in DATE_TIME format. Link to comment https://forums.phpfreaks.com/topic/64010-mysql-where-error/#findComment-319097 Share on other sites More sharing options...
teng84 Posted August 9, 2007 Share Posted August 9, 2007 have you tried using year something like year(date here) Link to comment https://forums.phpfreaks.com/topic/64010-mysql-where-error/#findComment-319098 Share on other sites More sharing options...
dcp Posted August 9, 2007 Share Posted August 9, 2007 If your data is in the datetime format (YYYY-MM-DD HH:MM:SS), you could probably use "LIKE" to get just the 2007 stuff: SELECT DISTINCT ( DATE_FORMAT( submitted, '%M' ) ) AS mymonth, DATE_FORMAT( submitted, '%Y' ) AS myyear, title FROM secondcitysaint WHERE submitted LIKE '2007%' ORDER BY submitted DESC LIMIT 0 , 30 Link to comment https://forums.phpfreaks.com/topic/64010-mysql-where-error/#findComment-319512 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.