How to put JSON into a column data if sub-query returns more than 1 row in MySQL
<p>I want to select portfolio of user with the same query that i used for select users.</p>

<p>Here the example that i want.</p>

<p>User Table</p>

<pre><code>----------------------------------------------------------------------
UID     NAME        USERNAME        EMAIL       PASSWORD        STATUS
----------------------------------------------------------------------
1       Manoj       manoj           a@a.com     ********        1
2       Test U      testing         b@a.com     ********        1
3       Company     user            c@a.com     ********        1
4       Agency      company         d@a.com     ********        1
</code></pre>

<p>User table in my database
<a href="https://i.stack.imgur.com/KwuGk.png" rel="noreferrer"><img src="https://i.stack.imgur.com/KwuGk.png" alt="User Table in my Database"></a></p>

<p>Portfolio Table</p>

<pre><code>-----------------------------------
PID     UID     TITLE       STATUS
-----------------------------------
1       1       title 1     1
2       1       title 2     1
3       1       title 3     1
4       2       title 1     1
</code></pre>

<p>Portfolio Table in my database
<a href="https://i.stack.imgur.com/nLA1Y.png" rel="noreferrer"><img src="https://i.stack.imgur.com/nLA1Y.png" alt="Portfolio Table"></a>
<strong>Result I want</strong> </p>

<pre><code>----------------------------------
UID     USERNAME        PORTFOLIO
----------------------------------
1       manoj           JSON OBJECT OF PID (1,2,3)
2       testing         JOSN OBJECT OF PID (4)
3       user            NULL
4       company         NULL
</code></pre>

<p>Currently I'm trying to use</p>

<pre><code>SELECT u.uid,u.username,(SELECT * FROM portfolio p WHERE u.UID=p.UID) as portfolio FROM users u
</code></pre>

<p>Is there any solution for this problem?</p>