Quantcast
Channel: Joomla! Forum - community, help and support
Viewing all articles
Browse latest Browse all 2381

Joomla! 4.x Coding • Re: How to write e.g. left join with nested select stetement?

$
0
0
Query objects are stringable. You can build the inner query and insert it into the outer query as a string:

Code:

$innerQuery->select('id_user, GROUP_CONCAT(t.name) AS concatenated_topics')    ->from('#__user_topics')    ->join('LEFT', '#__topics AS t', 't.id = id_topic')    ->group('id_user');$outerQuery->select('u.id, u.name AS user_name, t.concatenated_topics AS topics')    ->from('#__users AS u')    ->join('LEFT', '(' . $innerQuery . ') AS t', 't.id_user = u.id');
Note, if you have any parameters in the inner query, you have to bind them to the outer query.

Statistics: Posted by SharkyKZ — Mon Jun 10, 2024 7:57 pm



Viewing all articles
Browse latest Browse all 2381

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>