Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using "SELECT AS" alias in WHERE clause?

Status
Not open for further replies.

theotrain

Programmer
Mar 5, 2003
150
0
0
MX
i been trying to do this with no success:
[tt]
SELECT title, id, date_posted, MONTH(date_posted) AS month_posted, YEAR(date_posted) AS year_posted
FROM blog_posts
WHERE month_posted = 8
[/tt]
it seems to be choking on the "WHERE month_posted" part... which i actually want to use with a variable but im trying to get it going in the simplest possible form. tried it with single quotes around the 8 also.

is it really the case that you can't use an alias created using SELECT AS in your where clause? or am i just missing something?
 
Hi

theotrain said:
is it really the case that you can't use an alias created using SELECT AS in your where clause?
Usually yes, that is the problem. But we can not say that for sure as we not know what SQL is that.

However one thing is sure : your question is off-topic as it has nothing to do with PHP.

Feherke.
 
HA! yes thats quite true. i guess i was working in PHP and got bamboozled. in any case i figured it out and im amazed i didnt get it sooner. for any other lost souls you can simply use:

[tt]SELECT MONTH(date_posted) AS month_posted
FROM blog_posts
WHERE MONTH(date_posted) = 8[/tt]

just repeating the function in the where clause instead of using the alias.
 
doesn't that query just return a column of 8s?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top