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? Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
teng84 Posted August 9, 2007 Share Posted August 9, 2007 can you paste the exact error Quote Link to comment 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' Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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) Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.