Created
April 11, 2023 02:11
-
-
Save yarliganfatih/9a1b7b53c4db9dd4cfba851b38f40034 to your computer and use it in GitHub Desktop.
populate on SQL like NoSQL (with joined table)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
pt.*, | |
CONCAT( | |
'[', | |
GROUP_CONCAT( | |
JSON_OBJECT( | |
'id', ct.id, | |
'name', ct.name | |
) | |
), | |
']' | |
) AS childs --required | |
FROM parentTable pt | |
JOIN childTable ct | |
ON ct.parentTable_id = pt.id | |
GROUP BY pt.id --required |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://dbfiddle.uk/EzpL1aEe