INNER JOIN - Order of Columns & SQL Debugging

Screen Link:
Using SQL Joins To Combine Data From Two Tables | Dataquest

My Code:

SELECT f.name as country_name FROM facts f,  c.*
INNER JOIN cities c on c.facts_id = f.id
LIMIT 5;

What I expected to happen:

  1. I was expecting code to run successfully similar to DQ’s answer. The only variation between my code and DQ’s answer is in the first line of code. Only the output should have been different to DQ , but shouldn’t have given an error. What is the rationale ?

  2. Also, I also don’t understand how to debug SQL errors. Which documentation/websites to refer to ? The error background link seems puzzling to me

What actually happened:

(sqlite3.OperationalError) near "*": syntax error
[SQL: SELECT f.name as country_name FROM facts f,  c.* INNER JOIN cities c on c.facts_id = f.id LIMIT 5;]
(Background on this error at: http://sqlalche.me/e/13/e3q8)

DQ’s code is below. The only difference is that my code has c.* as second item in the first line of code. I was expecting only the order of country name column to be changed, but it gave an error

SELECT c.*, f.name country_name FROM facts f
INNER JOIN cities c ON c.facts_id = f.id
LIMIT 5;

I think you meant the following instead.

SELECT f.name as country_name, c.*
  FROM facts f
 INNER JOIN cities c
    ON c.facts_id = f.id
 LIMIT 5;

In your answer, you’re including c.* in the FROM clause.

Yeah, it’s pretty bad. That’s the best I have to give you with respect to SQL tracebacks.

Thanks that was stupid of me , to include c* in the FROM clause. Thanks