Retrieve (field) single value, from database using frappe.db.sql

Hi ERPNext Community

I Want to retrieve (min date) single value, from my doctype , how to fetch this field to another doctype ?
depend on student group

x = frappe.db.sql(""" select DISTINCT MIN(schedule_date) AS _start_date ....     
                                            where student_group = '{0}' """ .format(
                                            self.student_group,), as_dict=True)

I actually didn’t get you want single value from particular record or minimum date from whole list of records.

get_min_date = frappe.get_value(DocType, {"student_group": self.student_group}, ['schedule_date']) // For single record only

get_min_date_list = frappe.db.get_all(doctype, filters= { "student_group": self.student_group }, fields= ['schedule_date']) // From list of records

min([i.get('schedule_date', '') for i in get_min_date_list])
1 Like

@Hardik_Zinzu
Not Working Sir

What is not working and what issue you’re facing ? Please share screenshot.

1 Like

Hi @Hardik_Zinzu
Thank you for response
my code is

and I Want to retrieve to

@Hardik_Zinzu

thank you bro

my solution is

        if course_date:
            self.course_start_date = course_date[0].course_start_date
            self.course_end_date = course_date[0].course_end_date