Join 34,000+ subscribers and receive articles from our blog about software quality, testing, QA and security.

LEFT join in api


We’re looking to do a left join in our API so that a fetch of tests isn’t depdendent on a milestone being in place, however we do want to join to milestones when required.

	$this->db->select(' as milestone');	
	$this->db->join('milestones', ' = runs.milestone_id');

How can I change the last “join” to a left join?

Thank you


Hello Chris,

Thanks for your posting. There are two options here. There’s a simple ‘join_left’ method for this purpose or you can use the generic ‘query’ method (useful for more complex queries):

$query = $this->db->query( 'SELECT * FROM runs LEFT JOIN .. WHERE id = {0}', $some_run_id ); $runs = $query->result();

Possible arguments are replaced ({0}, {1}, {2}, …) and are also automatically quoted/escaped according to the format used by the underlying database (MySQL, SQL Server).

I hope this helps and please let me know in case you need anything else.