Answer the question
In order to leave comments, you need to log in
Doesn't SQLite3 support double (nested) INNER JOIN queries?
Some time ago it turned out that in my case it is more efficient to write RAW queries in Django than to use ORM: How to make a SQL query with INNER JOIN in Django through ORM? ...
Now faced with the fact that a relatively simple question does not want to be executed at all. The request is something like this:
SELECT TAB1.id, TAB2.id, TAB2.something, TABLINK1TO2.quantity
FROM TAB2
INNER JOIN (TAB1
INNER JOIN TABLINK1TO2
ON TAB1.id = TABLINK1TO2.link4tab1_id)
ON TAB2.id = TABLINK1TO2.link4tab2_id
WHERE TAB1.id=1
GROUP BY TAB1.id, TAB2.id, TAB2.something, TABLINK1TO2.quantity;
<RawQuerySet: 'the query actually sent here'>
no such column: TAB1.id
SELECT TAB2.id, TAB2.something, TABLINK1TO2.quantity
FROM TAB2
INNER JOIN TABLINK1TO2
ON TAB2.id = TABLINK1TO2.link4tab2_id
WHERE TABLINK1TO2.link4tab1_id=1
GROUP BY TAB2.id, TAB2.something, TABLINK1TO2.quantity;
Answer the question
In order to leave comments, you need to log in
A query like this works:
SELECT t1.id, t2.id, t2.something, t3.q
FROM t2 INNER JOIN t3 ON t2.id = t3.l2_id
INNER JOIN t1 ON t1.id = t3.l1_id
WHERE t1.id=1
GROUP BY t1.id, t2.id, t2.something, t3.q;
The error occurs because there is no id field in TAB1 (according to the error output no such column: TAB1.id). In a working query with one INNER JOIN, this field (and the table itself) does not appear at all.
If you are too lazy to drive in a request manually, then you can run the script from a file. On kraynyak, there is always a redirection of input / output streams.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question