Search
 
SCRIPT & CODE EXAMPLE
 

SQL

raw query must include primary key

queryset=country_model.objects.raw('SELECT myapp_country_model.cname,myapp_state_model.sname FROM myapp_country_model INNER JOIN myapp_state_model on myapp_country_model.id=myapp_state_model.cid_id')
Solution
queryset=country_model.objects.raw('SELECT myapp_country_model.id,myapp_country_model.cname,myapp_state_model.sname FROM myapp_country_model INNER JOIN myapp_state_model on myapp_country_model.id=myapp_state_model.cid_id ')
Comment

Raw query must include the primary key

Include 1 as id to your query

Message.objects.raw('''
        SELECT 1 as id , s1.ID, s1.CHARACTER_ID, MAX(s1.MESSAGE) MESSAGE, MAX(s1.c) occurrences
        FROM
           (SELECT ID, CHARACTER_ID, MESSAGE, COUNT(*) c
            FROM tbl_message WHERE ts > DATE_SUB(NOW(), INTERVAL %s DAY) GROUP BY CHARACTER_ID,MESSAGE) s1
        LEFT JOIN
           (SELECT ID, CHARACTER_ID, MESSAGE, COUNT(*) c
            FROM tbl_message WHERE ts > DATE_SUB(NOW(), INTERVAL %s DAY) GROUP BY CHARACTER_ID,MESSAGE) s2
          ON s1.CHARACTER_ID=s2.CHARACTER_ID
         AND s1.c < s2.c
        WHERE s2.c IS NULL
        GROUP BY CHARACTER_ID
        ORDER BY occurrences DESC''', [days, days]) 
Comment

PREVIOUS NEXT
Code Example
Sql :: case sensitive sql 
Sql :: sqlc yml settings version 1.14 
Sql :: oracle create chain rule 
Sql :: oracle update multiple columns 
Sql :: find Overlapping sql 
Sql :: sp help text in postgresql 
Sql :: get item by composite primary key mysql 
Sql :: how to add mysql to path on termin after installation 
Sql :: sql anywhere create procedure 
Sql :: sql get frist of month 
Sql :: http://localhost:9200/_cluster/allocation/explain 
Sql :: lesser than or equal to symbol in postgres 
Sql :: strftime format sqlite 
Sql :: what is logical database schema 
Sql :: order by length and alphabetical sql 
Sql :: tsql set database ownership 
Sql :: t-sql conditional order by multiple columns 
Sql :: get last query in codeigniter 4 
Sql :: check psql validity function 
Sql :: drop tables from local table database postgres 
Sql :: save_details_inrichting 
Sql :: sql view postgresql 
Sql :: power query case when 
Sql :: sql values that contains certain multiple ids 
Sql :: create trigger in phpmyadmin 
Sql :: get who is hired in february in sql 
Sql :: update mysql from paypal shopping cart and ipn 
Sql :: mysql docker image arjun 
Sql :: group function in sql 
Sql :: postgresql auto increment not working 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =