Search code examples
pythonsqlpandasjoinpandasql

Joining two tables using pandasql


I am running SQL queries in Python using Pandasql. The queries x, y and z work fine but u gives an error

x = pysql("select * from flight f left join iata i on f.ORIGIN = i.IATA;")

y = pysql("select * from flight f inner join iata i on f.ORIGIN = i.IATA;")

z = pysql("select * from flight, iata where flight.ORIGIN = iata.IATA;")

u = pysql("select * from flight f, iata i where f.ORIGIN = i.IATA;") 

The error message is

PandaSQLException: (sqlite3.OperationalError) no such table: iata [SQL: 'select * from flight f, iata i where f.ORIGIN = i.IATA;']

Question: What is wrong with u? It looks like we can use aliases in a join without mentioning left, right, inner etc. Is this true?


Solution

  • Because you must explicitly alias it with AS when using old style joins

    instead

    select * from flight f, iata i where f.ORIGIN = i.IATA;
    

    write

    select * from flight AS f, iata AS i where f.ORIGIN = i.IATA;