`$db_link->debug()->select("post", [
// Here is the table relativity argument that tells the relativity between the table you want to join.
// The row author_id from table post is equal the row user_id from table account
"[>]account" => ["author_id" => "user_id"],
// The row user_id from table post is equal the row user_id from table album.
// This is a shortcut to declare the relativity if the row name are the same in both table.
"[>]album" => "user_id",
// [post.user_id is equal photo.user_id and post.avatar_id is equal photo.avatar_id]
// Like above, there are two row or more are the same in both table.
"[>]photo" => ["user_id", "avatar_id"],
// If you want to join the same table with different value,
// you have to assign the table with alias.
"[>]account (replyer)" => ["replyer_id" => "user_id"],
// You can refer the previous joined table by adding the table name before the column.
"[>]account" => ["author_id" => "user_id"],
"[>]album" => ["account.user_id" => "user_id"],
// Multiple condition
"[>]account" => [
"author_id" => "user_id",
"album.user_id" => "user_id"
]
], [
"post.post_id",
"post.title",
"account.user_id",
"account.city",
"replyer.user_id",
"replyer.city"
], [
"post.user_id" => 100,
"ORDER" => "post.post_id DESC",
"LIMIT" => 50
]);`
Return Query
SELECT post"."post_id,post"."title,account"."user_id,account"."city,replyer"."user_id,replyer"."city FROM "post" LEFT JOIN "account" ON "post"."author_id" = "account"."user_id" AND "album"."user_id" = "account"."user_id" LEFT JOIN "album" ON "account"."user_id" = "album"."user_id" LEFT JOIN "photo" USING ("user_id", "avatar_id") LEFT JOIN "account" AS "replyer" ON "post"."replyer_id" = "replyer"."user_id" WHERE post"."user_id = 100 ORDER BY "post"."post_id" DESC LIMIT 50
MySQL say
Error (1064): Syntax error near 'post_id,post"."title,account"."user_id,account"."city,replyer"."user_id,replyer"' at line 1
From example http://medoo.in/api/select
`$db_link->debug()->select("post", [ // Here is the table relativity argument that tells the relativity between the table you want to join.
Return Query
SELECT post"."post_id,post"."title,account"."user_id,account"."city,replyer"."user_id,replyer"."city FROM "post" LEFT JOIN "account" ON "post"."author_id" = "account"."user_id" AND "album"."user_id" = "account"."user_id" LEFT JOIN "album" ON "account"."user_id" = "album"."user_id" LEFT JOIN "photo" USING ("user_id", "avatar_id") LEFT JOIN "account" AS "replyer" ON "post"."replyer_id" = "replyer"."user_id" WHERE post"."user_id = 100 ORDER BY "post"."post_id" DESC LIMIT 50
MySQL say