#Select rows with same id but different value in other columns.

2 messages · Page 1 of 1 (latest)

vapid thistle
#

I have some data in the postgres database that looks something like this.

The shareData table:

"id" "senderId" "applicationId" "recipients" "roomId"
1 1 1 "[{""userId"": 2}]" "6e25c3c3-6389-43ae-8be5-0ff091a828fd"
2 2 3 "[{""userId"": 1}]" "ed298b0c-734c-4d21-a847-5a10a6594dd8"
3 1 1 "[{""userId"": 3}]" "81cc7f78-785a-4340-830c-564469bd62ef"

The application table:

"id" "authorId" "applicationContent"
1 1 "<html><body>DUMMY</body></html>"
2 1 "<html><body>Test Data</body></html>"
3 2 "<html><body>Really dummy data</body></html>"
4 2 "<html><body>TEST DATA</body></html>"

I want to get all the applications data where user id matches whether it is in the application table's authorId (means user has created the application but have not shared it with anyone yet) or shareData tables senderId column or recipient column's userId field. Which is I am getting but the problem is I am getting the following response:

```{
        "data": [
            {
                "ApplicationId": 1,
                // ...other content of application
                "recipients": [
                    {
                        "userId": 3
                    },
                    {
                        "userId": 2
                    }
                ],
                "roomId": "81cc7f78-785a-4340-830c-564469bd62ef, 6e25c3c3-6389-43ae-8be5-0ff091a828fd",
                "User": {
                    //...user data
                }
            },
            //...other records
        ]
    }```
#

Look at the recipients and roomId field they are concatenated into 1 record as the application Id is the same but I want to separate them and want the response like following:

```{
    "data": [
        {
            "ApplicationId": 1,
            //...other content of application
            "recipients": [
                {
                    "userId": 2
                }
            ],
            "roomId": "6e25c3c3-6389-43ae-8be5-0ff091a828fd",
            "User": {
               //...user data
            }
        },
        {
            "ApplicationId": 1,
            //...other content of application
            "recipients": [
                {
                    "userId": 3
                }
            ],
            "roomId": "81cc7f78-785a-4340-830c-564469bd62ef",
            "User": {
                //...user data
            }
        },
        //...other records
    ]
}```