[Answered ]-Django MySQL raw query does not return results

1👍

Use LIKE instead of = when comparing Strings with wild cards

cursor.execute("SELECT b.spec_id, b.h_loss, c.gen_type FROM `db-dummy`.spec_gen_data c JOIN `db-dummy`.gen_info a ON a.record_id = c.gen_id JOIN `db-dummy`.spec_data b ON b.record_id = c.spec_id WHERE b.h_loss = 1 AND (a.ref_gen LIKE %s OR a.detail_ref_gen LIKE %s) AND c.gen_type BETWEEN 1 AND 5 ORDER BY a.gen_name;", ('{}%'.format(variant),'{}%'.format(variant),))
👤nbk

Leave a comment