1
votes

How come these commands give me " missing From clause"?!

select name,count(path) as num from authors join articles on author.id=articles.author join log on log.path=concat('/article/', articles.slug) group by authors.name order by num desc;


select title, count(path) as num from articles join authors on articles.author = authors.id join log on log.path = concat('/article/',articles.slug) group by title, path, authors.name order by num desc limit 3;

Here is my complete python code tho:


import psycopg2
db = psycopg2.connect(database="news")
c=db.cursor()
c.execute("""
    select title, count(path) as num from articles join authors on articles.author = authors.id join log on log.path = concat('/article/',articles.slug) group by title, path, authors.name order by num desc limit 3;

    """)
c.execute("""select name,count(path) as num from authors join articles on author.id=articles.author join log on log.path=concat('/article/', articles.slug) group by authors.name order by num desc;""")
rows=c.fetchall()
print (rows)
db.close

The error that shows is the following: psycopg2.errors.UndefinedTable: missing FROM-clause entry for table "authors" LINE 1: ...,count(path) as num from authors join articles on author.id=...

1
What version of SQL are you using? (I'm guessing either MySQL, Postgres, or SQLite). - Tim Biegeleisen
It's postgres..... - Rania
I see nothing obviously wrong. You might want to give us a complete reproducible example, including some sample data. - Tim Biegeleisen
have you tried rows=list(c)? - Ed Bangga
Possibly its the non-plural author in ON clause. Make sure it references authors. - Parfait

1 Answers

0
votes

author.id should be changed to authors.id