Skip to content

Instantly share code, notes, and snippets.

@yarliganfatih
Created April 11, 2023 02:11
Show Gist options
  • Save yarliganfatih/9a1b7b53c4db9dd4cfba851b38f40034 to your computer and use it in GitHub Desktop.
Save yarliganfatih/9a1b7b53c4db9dd4cfba851b38f40034 to your computer and use it in GitHub Desktop.
populate on SQL like NoSQL (with joined table)
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
@yarliganfatih
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment