{"action":"closed","issue":{"url":"https://api.github.com/repos/joshcam/PHP-MySQLi-Database-Class/issues/195","labels_url":"https://api.github.com/repos/joshcam/PHP-MySQLi-Database-Class/issues/195/labels{/name}","comments_url":"https://api.github.com/repos/joshcam/PHP-MySQLi-Database-Class/issues/195/comments","events_url":"https://api.github.com/repos/joshcam/PHP-MySQLi-Database-Class/issues/195/events","html_url":"https://github.com/joshcam/PHP-MySQLi-Database-Class/issues/195","id":57694462,"number":195,"title":"Subquery in join","user":{"login":"Ettemlevest","id":1035942,"avatar_url":"https://avatars.githubusercontent.com/u/1035942?v=3","gravatar_id":"","url":"https://api.github.com/users/Ettemlevest","html_url":"https://github.com/Ettemlevest","followers_url":"https://api.github.com/users/Ettemlevest/followers","following_url":"https://api.github.com/users/Ettemlevest/following{/other_user}","gists_url":"https://api.github.com/users/Ettemlevest/gists{/gist_id}","starred_url":"https://api.github.com/users/Ettemlevest/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Ettemlevest/subscriptions","organizations_url":"https://api.github.com/users/Ettemlevest/orgs","repos_url":"https://api.github.com/users/Ettemlevest/repos","events_url":"https://api.github.com/users/Ettemlevest/events{/privacy}","received_events_url":"https://api.github.com/users/Ettemlevest/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-02-14T14:23:33Z","updated_at":"2015-04-20T21:32:02Z","closed_at":"2015-04-20T21:32:02Z","body":"Is there a way to put a subquery into a join? I'm trying to figure out what is my mistake. Here's my raw query that I would like to convert:\r\n```\r\nSELECT m.*, kapcsolattartok\r\nFROM megbizok m\r\n\tLEFT JOIN (\r\n\t\tSELECT k.megbizo_id, COUNT(k.kapcsolattarto_id) AS kapcsolattartok FROM megbizok_kapcsolattartok k GROUP BY k.megbizo_id\r\n\t) AS k ON m.megbizo_id = k.megbizo_id\r\nWHERE\r\n\tm.torolve = 0\r\nORDER BY m.megbizo_megnevezes, m.megbizo_azonosito\r\n```\r\nThis is how I tryied it with PHP-MySQLi-Database-Class:\r\n```\r\n$kapcsolattartok = $db->subQuery();\r\n$kapcsolattartok\r\n\t->groupBy('k.megbizo_id')\r\n\t->get('megbizok_kapcsolattartok k', null, 'k.megbizo_id, COUNT(k.kapcsolattarto_id) AS kapcsolattartok');\r\n\r\n$data = $db\r\n\t->join($kapcsolattartok, 'm.megbizo_id = k.megbizo_id', 'LEFT')\r\n\t->where('m.torolve', 0)\r\n\t->orderBy('m.megbizo_megnevezes')\r\n\t->orderBy('m.megbizo_azonosito')\r\n\t->get('megbizok m');\r\n```\r\n\r\nBut it generates a fatal error:\r\nProblem preparing query (SELECT * FROM megbizok m LEFT JOIN  on m.megbizo_id = k.megbizo_id WHERE   m.torolve = ?  ORDER BY m.megbizo_megnevezes DESC, m.megbizo_azonosito DESC )\r\n\r\nIt looks like the subquery's string missing from the join. I did not find any information about this kind of problem."}}