Problem solve Get help with specific problems with your technologies, process and projects.

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 last published in April 2005

Dig Deeper on Oracle and SQL



Find more PRO+ content and other member only offers, here.

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.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.