Join tables using django raw query

Viewed 16

what's wrong with the below query? I want to get the feedback_date from pages_dcb table for all the dials that are in the pages_dataupload table where the registration date of the dials are in the 2022.

SELECT pages_dataupload.Dial, pages_dataupload.Registration_Date
FROM pages_dataupload WHERE pages_dataupload.Registration_Date >=  '2022-01-01'
LEFT JOIN (
SELECT pages_bdc.Dial, pages_bdc.feedback_date
) on pages_dataupload.Dial = pages_bdc.Dial;

Error

Execution finished with errors.
Result: near "LEFT": syntax error
At line 1:
SELECT pages_dataupload.Dial, pages_dataupload.Registration_Date
FROM pages_dataupload WHERE pages_dataupload.Registration_Date >=  '2022-01-01'
LEFT

and when I add the WHERE clause after join it says no such column called Dial

SELECT Dial, Registration_Date FROM pages_dataupload as t1
LEFT JOIN (
SELECT Dial, feedback_date FROM pages_bdc as t2
) on t1.Dial = pages_bdc.Dial WHERE t1.Registration_Date >=  '2022-01- 
01';

Error

Execution finished with errors.
Result: ambiguous column name: Dial
At line 1:
SELECT Dial, Registration_Date FROM pages_dataupload as t1
LEFT JOIN (
SELECT Dial, feedback_date FROM pages_bdc as t2
) on t1.Dial = pages_bdc.Dial WHERE t1.Registration_Date >=  '2022-01- 
01';
0 Answers
Related