Mysql Select Join Operation


Select records from the multiple table with join keyword. You can provide columns to be selected and where clause with associative array of conditions with keys as columns and value as column value, group by, order by , limit etc. You needs to specify join condition between different tables and join type (LEFT JOIN,RIGHT JOIN etc.) to select data. This function will automatically creates query for you and select data.

Function Reference :
          	resource/array dbSelectJoin(string $table_names, array $join_conditions, array $join_type [, array $columns=array()] [, assoc. array $select_where_condition=array()]) 


Name Type Required Parameter Info Example
table_name array Yes The name of the table to insert new records any table name like array("employee_table","user_table")
join_conditions array Yes Array of join conditions between tables. array("users.role_id=user_roles.role_id")
join_type array Yes Array of join types array("INNER JOIN","LEFT JOIN")
columns_array array Optional Array of columns to be selected array("firstname","lastname","role_name","blog_title")
select_where_condition associative array Optional Associative array with key as column name and values as column value for where clause. array("gender"=>"male")


             $sdb= new SimplifiedDB();
             $tables=array("users", "user_roles","user_blogs");
             $join_condition=array("LEFT JOIN","RIGHT JOIN");


Returns mysql result set by default. You can set $sdb->output_array=true, to return array as output.
If you use print_r($row) in
while($row = mysql_fetch_array($result)) {
it will show output as in following format.

Array ( [0] => Ram [firstName] => Ram [1] => [email] => ) Array ( [0] => Sachine [firstName] => Sachine [1] => [email] => )


Debug Operation Result/Output
$sdb->query SELECT `firstName`,`email` FROM `users` LEFT JOIN `user_roles` ON users.role_id=user_roles.roleid RIGHT JOIN `user_blogs` ON users.userid=user_blogs.userid
$sdb->message_info Connected to database

More Examples

             $tables=array("users", "user_roles");
             $join_condition=array("LEFT JOIN");
             $columns=array("firstName", "email", "role_name","blogTitle","content");