Self joining returns unnecessary data

#1

Hi,

I get unnecessary data when I run a self joining query.

Dataset

Key: post.1
Content: 
{
  "name": "post 1"
}


Key: like.1 
Content: 
{
    "postId": "post.1"
}

Key: like.2
Content:
{
    "postId": "post.1"
}

Query: select * from default default1 join default default2 on keys default1.postId

Output:

"results": [
{
    "default1": {
        "postId": "post.1"
    },
    "default2": {
        "name": "post 1"
    }
},
{
    "default1": {
        "postId": "post.1"
    },
    "default2": {
        "name": "post 1"
    }
}
    ],

How do I avoid having “default1” ?

I only want to get content from post.1 document.

#2

You’re using SELECT * so you’ll get everything back. You should be able to use SELECT default2.* instead, and only receive the data you want.

#3

Try

select default2.* from default default1 join default default2 on keys default1.postId;

or

select default1.* from default default1 join default default2 on keys default1.postId;

One of these should give you what you want. The problem is that you are doing select *.

#4

Thank you daves. That worked for me:)

#5

Thank you geraldss! That works for me :smile:

#6

@daves, I missed your earlier reply and posted a dup. Welcome to the forums :smile: