I have a course table, each course has an id, a code and a start date. Example:
course_id course_code start_date
uuid1 course_a 2021-06-01
uuid2 course_a 2021-09-01
uuid3 course_b 2021-06-01
uuid4 course_b 2021-09-01
I want to get the latest record of each distinct course and I can do it in SQL
SELECT DISTINCT ON (course_code)
course_id,
course_code,
start_date
FROM course
ORDER BY course_code, start_date DESC
uuid2 course_a 2021-09-01
uuid4 course_b 2021-09-01
But is it possible to query in graphql?
Solved by adding a list of order_by condition instead of unordered object
query MyQuery {
course(distinct_on: course_code, order_by: [{course_code: asc}, {start_date: desc}]) {
course_id
course_code,
start_date
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With