SQL Queries (API v2 vs v3)

This page is here to highlight SQL query syntax differences illustrating the changes made to the Ilios database schema. This happens along with our switching of the API from the old version (v2) to the new version (v3).

The database schema you know and love will be available until the end of the year. We have made some changes to make retrieving data from Ilios easier, especially regarding Course, Session, and Program Year Objectives. There are other small changes, but the primary changes were made in the realm of Objectives.

The tables objective_x_objective, objective and session_description have been removed as of 1/29/2021. Some of the potential SQL query syntax changes that may be necessary as a result of these tables being removed, along with the other schema changes, are detailed below.

Course Objectives

Sample SQL Query

/** This is for new and old syntaxes for retrieving Objective records 
from Ilios -- going to use a place holder for course_id [course_id]
any valid course ID can be used **/

/** new method - API v3 - retrieve course objectives **/
/** only need to query one table `course_x_objective` **/
SELECT course_objective_id, title 
  FROM course_x_objective 
WHERE course_id = [course_id];

/** old method - API v2 - course objectives **/
SELECT o.objective_id, o.title 
  FROM objective o 
  JOIN course_x_objective cxo 
    ON cxo.objective_id = o.objective_id
WHERE cxo.course_id = [course_id];

Tables Affected - Course Objective Query

In the Course Objective query outlined above, it is important to note the changes that are taking place with the design of the course_x_objective table in particular.

v2 Schema (old) - course_x_objective

v3 Schema (new) - course_x_objective

Additional fields that are available in course_x_objectivein the new version of the database schema without having to join to other tables: ancestor_id, title, and active. Title is the big win here. Objectives are no longer stored in one location objectives and there is now no need to join to that table in order to retrieve Course Objectives.

Session Objectives

Sample SQL Query

Tables Affected - Session Objective Query

In the Session Objective query outlined above, it is important to note the changes that are taking place with the design of the session_x_objective table in particular. The only reason a join to the session table was performed is that we were running our query passed upon the course_id field as a parameter and that field is contained in the session table.

v2 Schema (old) - session_x_objective

v3 Schema (new) - session_x_objective

Additional fields that are available in session_x_objective in the new version of the database schema without having to join to other tables: ancestor_id, title, and active. Title is the big win here. Objectives are no longer stored in one location objectives and there is now no need to join to that table in order to retrieve Session Objectives.

This also makes it easier to deal with Parent Objectives as we will soon see.

Session Objectives with Course Objectives

This next one will return all Session Objectives with their parent (Course) Objectives as well, whether this parentage has been established or not. In this case, the queries will be separated into their own code blocks with comments.

Sample SQL Query (v2 - Old Schema)

In the example below, we had to join to the objective table twice - once to return the Session Objectives and again to return the Course Objectives. The parent relationship between these two Objective levels is defined using the objective_x_objective table. The field parent_objective_id returns the ID values used to join to objective to retrieve the Objective details.

Sample Query (v3 - New Schema)

In the example below, there is no need to join to either objective or objective_x_objective, both of which will be removed at the end of the year. Left outer joins are performed similarly in both versions of this query in order to return Session Objectives that are NOT linked to Course Objectives.

Program Year Objectives

Sample SQL Query

Session Objectives with Course Objectives and Program Year (Parent) Objectives

Sample SQL Query (v2 - Old Schema)

NOTE: These v2 Queries will no longer run after the end of 2020.

Sample SQL Query (v3 - New Schema)

Last updated