This website uses cookies. By clicking Accept, you consent to the use of cookies. Click Here to learn more about how we use cookies.

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results forΒ

- Neo4j
- Technical Discussions
- Neo4j Graph Platform
- Why does this two queries produce "inconsistent" r...

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Options

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

β03-30-2021 05:53 PM

`match (m:Product) return count(m)`

And

```
MATCH p=(m:Product)-[r:competitiveProduct]->(:Product)
RETURN distinct count(m)
```

The 1st generates 84749 and the 2nd generates 123039. I thought the two numbers should be the same or the 2nd number should be equal or less than the first. However, the 2nd is much larger. Why is that?

Solved! Go to Solution.

1 ACCEPTED SOLUTION

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

β03-31-2021 11:38 AM

as you initially stated

I thought the two numbers should be the same or the 2nd number should be equal or less than the first.

well they can not be the same or at least my example above demonstrates why they are not the same.

But also as to why the 2nd is larger than the first and using a new database and under 4.2.3 if I run

```
// insure the database is empty
match (n) detach delete n;
// populate some data
create (n:Product {id:1});
create (n:Product {id:2});
create (n:Product {id:3});
match (n:Product {id:1}), (n2:Product {id:2}) create (n)-[:competitiveProduct]->(n2);
match (n:Product {id:1}), (n2:Product {id:3}) create (n)-[:competitiveProduct]->(n2);
match (n:Product {id:2}), (n2:Product {id:3}) create (n)-[:competitiveProduct]->(n2);
match (n:Product {id:3}), (n2:Product {id:1}) create (n)-[:competitiveProduct]->(n2);
match (n:Product {id:2}), (n2:Product {id:1}) create (n)-[:competitiveProduct]->(n2);
// now run the 2 queries in question
match (n:Product) return count(n);
MATCH p=(m:Product)-[r:competitiveProduct]->(:Product)
RETURN distinct count(m);
```

this results in output of

```
count(n)
3
count(m)
5
```

maybe the next question is what is the question you are attempting to ask of the database and via a cypher statement.

The first cypher you provided simply provides the number of :Product nodes.

also, your initial 2nd cypher should probably be

```
return count( distinct m);
```

6 REPLIES 6

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

β03-30-2021 06:52 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

β03-30-2021 08:03 PM

@duane That's not happening with my case. I ran the two queries almost the same time.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

β03-31-2021 03:24 AM

the 2 queries are very different

the first simply returns the number of :Product nodes. For example f I run

```
unwind range (1,1000) as x create (n:Product {id:x});
```

this creates 1000 :Product nodes and thus a

```
match (n:Product ) return count(n);
```

will return 1000.

However

```
MATCH p=(m:Product)-[r:competitiveProduct]->(:Product)
RETURN distinct count(m);
```

requires a :Product node must have a :competitveProduct relationship.

So if all I do is run the `unwind`

as above then the 1st statement will return a value of 1000 and the second will return a value of 0 but this is expected since the queries are very different

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

β03-31-2021 10:55 AM

@dana.canzano You are right, and that's why I said the result count for the 2nd should be = or less then the first one, but my queries shows the opposite:

"The 1st generates 84749 and the 2nd generates 123039. I thought the two numbers should be the same or the 2nd number should be equal or less than the first. However, the 2nd is much larger."

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

β03-31-2021 11:38 AM

as you initially stated

I thought the two numbers should be the same or the 2nd number should be equal or less than the first.

well they can not be the same or at least my example above demonstrates why they are not the same.

But also as to why the 2nd is larger than the first and using a new database and under 4.2.3 if I run

```
// insure the database is empty
match (n) detach delete n;
// populate some data
create (n:Product {id:1});
create (n:Product {id:2});
create (n:Product {id:3});
match (n:Product {id:1}), (n2:Product {id:2}) create (n)-[:competitiveProduct]->(n2);
match (n:Product {id:1}), (n2:Product {id:3}) create (n)-[:competitiveProduct]->(n2);
match (n:Product {id:2}), (n2:Product {id:3}) create (n)-[:competitiveProduct]->(n2);
match (n:Product {id:3}), (n2:Product {id:1}) create (n)-[:competitiveProduct]->(n2);
match (n:Product {id:2}), (n2:Product {id:1}) create (n)-[:competitiveProduct]->(n2);
// now run the 2 queries in question
match (n:Product) return count(n);
MATCH p=(m:Product)-[r:competitiveProduct]->(:Product)
RETURN distinct count(m);
```

this results in output of

```
count(n)
3
count(m)
5
```

maybe the next question is what is the question you are attempting to ask of the database and via a cypher statement.

The first cypher you provided simply provides the number of :Product nodes.

also, your initial 2nd cypher should probably be

```
return count( distinct m);
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

β03-31-2021 12:18 PM

Nodes 2022

OnΒ November 16 and 17 for 24 hours across all timezones, youβll learn about best practices for beginners and experts alike.

Related Content

- Increase query performance in Neo4j Graph Platform
- NEO4J Sink and Source connector in Neo4j Graph Platform
- Getting "The transaction has been closed." error while projecting a subgraph with GDS in Neo4j Graph Platform
- Neo4j LOAD CSV..when CSV columns contains a list of properties in Neo4j Graph Platform
- how create cypher query with conditional filters in Drivers & Stacks