Repository: macbre/sql-metadata

Issue:
Cannot access columns before tables
This code

```
from sql_metadata import Parser

sql1 =  "SELECT loan.loan_id, district.a3 AS district, district.a11 AS average_salary FROM loan INNER JOIN account ON loan.account_id = account.account_id INNER JOIN district ON account.district_id = district.district_id WHERE loan.duration = 60\n"
  
p = Parser(sql1)

print(p.tables)
print(p.columns)

```

works correctly, but this

```
from sql_metadata import Parser

sql1 =  "SELECT loan.loan_id, district.a3 AS district, district.a11 AS average_salary FROM loan INNER JOIN account ON loan.account_id = account.account_id INNER JOIN district ON account.district_id = district.district_id WHERE loan.duration = 60\n"
  
p = Parser(sql1)

print(p.columns)
print(p.tables)

```

throws 

`KeyError: 'INNERJOIN'
`

Discussion:

Fix (patch):
diff --git a/sql_metadata/keywords_lists.py b/sql_metadata/keywords_lists.py
index 4414356..5585784 100644
--- a/sql_metadata/keywords_lists.py
+++ b/sql_metadata/keywords_lists.py
@@ -65,6 +65,7 @@ COLUMNS_SECTIONS = {
     "INTO": "insert",
     "SET": "update",
     "GROUPBY": "group_by",
+    "INNERJOIN": "inner_join",
 }
 
 


Test changes:
diff --git a/test/test_getting_columns.py b/test/test_getting_columns.py
index 7453176..ab89148 100644
--- a/test/test_getting_columns.py
+++ b/test/test_getting_columns.py
@@ -528,3 +528,16 @@ def test_nested_queries():
     parser = Parser(query)
     assert parser.columns == ["dt"]
     assert parser.columns_dict == {"select": ["dt"]}
+
+
+def test_double_inner_join():
+    query = """
+    SELECT loan.loan_id, district.a3 AS district, district.a11 AS average_salary
+        FROM loan
+        INNER JOIN account ON loan.account_id = account.account_id
+        INNER JOIN district ON account.district_id = district.district_id WHERE loan.duration = 60
+    """
+
+    parser = Parser(query)
+    assert "loan.account_id" in parser.columns
+    assert parser.tables == ["loan", "account"]