1

I have a table containing this three field , nodes, Memeber_id, id .there is two repetitive rows of id in entire table. Based on this id value in id column I want to find repetitive value in node array. for eg . -169116 id represents two nodes array {-167486,-49628} and {-43815,-49625,-49626,-49627,-49628} In both the array common value is -49628. so it should select -169116 id and -49628 value from array.

enter image description here

1 Answer 1

2

Unnest the array and then simply group by count(node) > 1:

select node, id, count(*) 
from (select unnest(nodes) as node, member_id, id from node_test) as g
group by node, id having count(node) > 1;

This results in:

  node  |   id    | count
--------+---------+-------
 -49628 | -169116 |     2
Sign up to request clarification or add additional context in comments.

1 Comment

This is exactly what I wanted @Julia Leder. Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.