Skip to content
Advertisement

How to select data depending on data from the same table with custom field in SELECT?

I have a query to fetch closest airports to the airport:

Where 55.966324 and 37.416573 are latitude and longitude of the airport I’m searching neighbour airports for. But in order to get those coordinates I would need to fetch that airport data first in a separate query which would slow things down. I would like to make this operation in a single query knowing only airport code, so I wrote the following SQL query:

But it doesn’t work. My database only shows me the error:

What am I doing wrong with my query? MySQL Workbench seems to be OK with syntax.

Advertisement

Answer

Error 1052 in mysql indicates that a reference is ambiguous (see https://dev.mysql.com/doc/mysql-errors/5.7/en/server-error-reference.html) Qualify all columns in your expression with the correct alias, like:

I

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement