Q

Using a column alias

Here is my SQL:

 SELECT fho$-wxbo$ as amt FROM wip220, frp001 WHERE wxot=fhot and wxpro=fhpro and wxrdat between 1050401 and 1050404 and amt > 0

I get the error: "Column AMT not in specified tables" and I don't know how to fix it.

You cannot use a column alias in the WHERE clause. Change your query to:

 select fho$-wxbo$ as amt from wip220, frp001 where wxot=fhot and wxpro=fhpro and wxrdat between 1050401 and 1050404 and fho$-wxbo$ > 0

The reason for this restriction on the alias comes from the way in which queries are executed. The first step in execution is the FROM clause, as modified by the WHERE clause. Next, the GROUP BY clause is executed, followed by the HAVING clause. Then, the SELECT list is evaluated, and finally, the ORDER BY clause. So you see, at the time the WHERE clause is evaluated, the database optimizer doesn't recognize the alias name. Note that you can use the alias in the ORDER BY.

This was first published in April 2005

Dig deeper on Oracle and SQL

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close