General developer forum

Join tables without raw SQL query

 
Picture of Bahriddin Abdiev
Join tables without raw SQL query
 

Is there any method or function to get joined results from the databases? I wrote this question on the stack overflow with more details: https://stackoverflow.com/questions/45726399/moodle-join-tables-without-raw-sql-query

Answer in anywhere is highly appreciated!

Thank you!

 
Average of ratings: -
Davo
Re: Join tables without raw SQL query
Core developersParticularly helpful MoodlersPlugin developers

No.

The DB API is there to simplify many common situations (e.g. getting one or more records from a single table), but if you need to gather data from more than one table at once, then you need to use $DB->get_records_sql() (or similar).

However, if you want a list of users in a particular course, then use the get_enrolled_users() function, rather than trying to manually write the SQL query for it.

 
Average of ratings: Useful (1)
Picture of Bahriddin Abdiev
Re: Join tables without raw SQL query
 

Thank you, Davo Smith. It was really helpful.

 
Average of ratings: -