# Cypher Query to to get having minimum 2 edges?

**URL:** <https://community.neo4j.com/t/cypher-query-to-to-get-having-minimum-2-edges/10269>\
**Category:** Neo4j Graph Platform\
**Created:** [September 20, 2019, 5:04am UTC](https://community.neo4j.com/t/cypher-query-to-to-get-having-minimum-2-edges/10269 "2019-09-20T05:04:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![apremgeorge](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/apremgeorge/32/6388_2.png) [@apremgeorge](https://community.neo4j.com/u/apremgeorge)\
**Post date:** [September 20, 2019, 5:04am UTC](https://community.neo4j.com/t/cypher-query-to-to-get-having-minimum-2-edges/10269/1 "2019-09-20T05:04:55Z")

</div>

Hi,  
Q1: May I know cypher query to find the nodes having minimum 2 edges, either 2 In minimum, or 1 in and 1 out minimum?  
based on Degree, I did that, i.e having deg \> 2, but without running degree algorithm

Thanks

---

<div class="post-metadata">

**Author:** ![stefan.armbruster](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/stefan.armbruster/32/74_2.png) [@stefan.armbruster](https://community.neo4j.com/u/stefan.armbruster)\
**Post date:** [September 20, 2019, 3:47pm UTC](https://community.neo4j.com/t/cypher-query-to-to-get-having-minimum-2-edges/10269/2 "2019-09-20T15:47:43Z")

</div>

```auto
MATCH (n) WHERE size( (n)--() ) > 2 RETURN n

```

should do the trick.

---

<div class="post-metadata">

**Author:** ![bhooyman](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/bhooyman/32/4623_2.png) [@bhooyman](https://community.neo4j.com/u/bhooyman)\
**Post date:** [September 27, 2019, 8:25pm UTC](https://community.neo4j.com/t/cypher-query-to-to-get-having-minimum-2-edges/10269/3 "2019-09-27T20:25:03Z")

</div>

That’s a full scan of the relationships file, correct? Even worse, most likely a full scan of the nodes file, plus a relationship pointer chase for each node.

---

<div class="post-metadata">

**Author:** ![stefan.armbruster](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/stefan.armbruster/32/74_2.png) [@stefan.armbruster](https://community.neo4j.com/u/stefan.armbruster)\
**Post date:** [September 29, 2019, 7:22am UTC](https://community.neo4j.com/t/cypher-query-to-to-get-having-minimum-2-edges/10269/4 "2019-09-29T07:22:44Z")

</div>

No. "Just" a full scan of nodes file. Getting the degree of a node is a `O(n)` operation for `n<50` and a `O(1)` for `n>=50`.

---

<div class="post-metadata">

**Author:** ![bhooyman](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/bhooyman/32/4623_2.png) [@bhooyman](https://community.neo4j.com/u/bhooyman)\
**Post date:** [September 29, 2019, 8:01am UTC](https://community.neo4j.com/t/cypher-query-to-to-get-having-minimum-2-edges/10269/5 "2019-09-29T08:01:20Z")

</div>

That’s interesting. I thought I understood Neo4j internals and file record layout.

Can you educate me? Or tell me what part of the documentation I missed?

Thx

---

<div class="post-metadata">

**Author:** ![dana\_canzano](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/dana_canzano/32/27392_2.png) [@dana\_canzano](https://community.neo4j.com/u/dana_canzano)\
**Post date:** [September 29, 2019, 11:03am UTC](https://community.neo4j.com/t/cypher-query-to-to-get-having-minimum-2-edges/10269/6 "2019-09-29T11:03:11Z")

</div>

Neo4j records a pre-calculated value for the following

Count of Nodes , i.e. match (n) return count(n);  
Count of Nodes per label, i.e. match (n:Person) return count(n);  
Count of relationship types per Node and direction, i.e. match (n) return size( (n)-[:FOLLOWS]-\>() );

if you `PROFILE` or `EXPLAIN` the above Cypher statements you should see a block referring to 'CountStore'

---

<div class="post-metadata">

**Author:** ![bhooyman](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/bhooyman/32/4623_2.png) [@bhooyman](https://community.neo4j.com/u/bhooyman)\
**Post date:** [September 30, 2019, 8:52am UTC](https://community.neo4j.com/t/cypher-query-to-to-get-having-minimum-2-edges/10269/7 "2019-09-30T08:52:27Z")

</div>

Super! Which version of Neo4j introduced this?

---

<div class="post-metadata">

**Author:** ![dana\_canzano](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/dana_canzano/32/27392_2.png) [@dana\_canzano](https://community.neo4j.com/u/dana_canzano)\
**Post date:** [September 30, 2019, 5:54pm UTC](https://community.neo4j.com/t/cypher-query-to-to-get-having-minimum-2-edges/10269/8 "2019-09-30T17:54:53Z")

</div>

introduced what?  
the precalculated values at

```auto
Count of Nodes , i.e. match (n) return count(n);
Count of Nodes per label, i.e. match (n:Person) return count(n);
Count of relationship types per Node and direction, i.e. match (n) return size( (n)-[:FOLLOWS]->() );

```

has been in Neo4j since at least Neo4j version 2.3, if not earlier
