Here is my SQL:
By submitting your email address, you agree to receive emails regarding relevant topic offers from TechTarget and its partners. You can withdraw your consent at any time. Contact TechTarget at 275 Grove Street, Newton, MA.
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.
Related Q&A from Rudy Limeback
Read SQL expert Rudy Limeback's advice for counting combinations in a table with SQL's GROUP BY clausecontinue reading
Read an example of an SQL case expression from our SQL expert Rudy Limeback.continue reading
Read about the Mimer Validator, a tool used to verify your SQL code, in this tip from SQL expert Rudy Limeback.continue reading
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.