cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Doubt with "Finding Duplicate" Cypher Query

sucheta
Graph Buddy

Hi,

I have created a network using the following queries -


CREATE (cc:Organisation { name: "Century", dealing: "Cement", formed:1974 });
Match (cc:Organisation) WHERE cc.name = "Century"
CREATE (eway:EwayBill {name:"EwayBill", type:"Outbound", connectedTo:"SAP"}),
(sms:SMS {name:"SMS", type:"Outbound", connectedTo:"SAP"}),
(collection:Collection {name:"Collection", type:"Inbound", connectedTo:"SAP"}),
(payments:Payments {name:"Payments", type:"Outbound", connectedTo:"SAP"}),
(cc)-[:System]->(eway),(cc)-[:System]->(sms),(cc)-[:System]->(payments),(cc)-[:System ]->(collection);
MATCH (eway:EwayBill) WHERE eway.name="EwayBill"
CREATE (generate:Generate {name:"Generate", description:"Generate an Eway Bill"}),
(update:Update {name:"Update", description:"Update Vehicle Number"}),
(cancel:Cancel {name:"Cancel", description:"Cancel an  Eway Bill"}),
(eway)-[:Method]->(generate),(eway)-[:Method]->(update),(eway)-[:Method]->(cancel);

MATCH (generate: Generate) WHERE generate.name="Generate"
CREATE (pan: Pan {name:"Pan", description:"Generate a PanCard"}),
(drivingl:DrivingLicense {name:"DrivingLicense", description:"Generate a Driving License"}),
(aadhaar:Aadhar {name:"Aadhar", description:"Generate an Aadhaar Number"}),
(generate)-[:Attribute]->(pan),(generate)-[:Attribute]->(drivingl),(generate)-[:Attribute]->(aadhaar);


MATCH (update: Update) WHERE update.name="Update"
CREATE (pan: Pan {name:"Pan", description:"Generate a PanCard"}),
(drivingl:DrivingLicense {name:"DrivingLicense", description:"Generate a Driving License"}),
(aadhaar:Aadhar {name:"Aadhar", description:"Generate an Aadhaar Number"}),
(update)-[:Attribute]->(pan),(update)-[:Attribute]->(drivingl),(update)-[:Attribute]->(aadhaar);

Here is the Network -

My query like this below reference to find any duplicate -


MATCH (js:Person)-[:KNOWS]-()-[:KNOWS]-(surfer)
WHERE js.name = "Johan" AND surfer.hobby = "surfing"
RETURN DISTINCT surfer

is

MATCH (js:EwayBill)-[:Attribute]-()-[:Attribute]-(findaadhar)
WHERE js.name = "EwayBill" AND findaadhar.name = "Aadhar"
RETURN DISTINCT findaadhar

But it shows response as -

(no changes, no records)

Please help with the formation of the duplicate query.

1 ACCEPTED SOLUTION

MATCH pathx=(n:Organization)-[*1..3]-(m) RETURN pathx

this will give you all nodes up to 3 hops from the starting node ...

View solution in original post

9 REPLIES 9

The central EwayBill node is not linked to any other nodes via a link of type :Attribute

So the query should be ...

MATCH (js:EwayBill)--()-[:Attribute]-(findaadhar)
WHERE js.name = "EwayBill" AND findaadhar.name = "Aadhar"
RETURN DISTINCT findaadhar

Thanks paul.
But i am facing the issue with the Neo4j desktop version itself.
This is the output with the query

MATCH (js:EwayBill)--()-[:Attribute]-(findaadhar)
WHERE js.name = "EwayBill" AND findaadhar.name = "Aadhar"
RETURN DISTINCT findaadhar

->

I am facing this issue from a long time . I donot get proper outputs to the queries. Like -

When i type --> MATCH (n) RETURN n

My colleagues get the entire network with relationships, but i get only nodes.

Please suggest a solution.

RETURN DISTINCT findaadhar

will only return the end nodes ...
run this instead to see the full paths ...

MATCH pathx=(js:EwayBill)--()-[:Attribute]-(findaadhar)
WHERE js.name = "EwayBill" AND findaadhar.name = "Aadhar"
RETURN pathx

Thanks Paul.

How about this following query -->

MATCH (n) RETURN n

I want to use this query in my application. My colleagues get a proper linked to all nodes output . But i get only nodes as shown above

Please help,

MATCH (n) RETURN n

if you have 1000s of nodes in the graph, only a subset are returned based on max nodes setting in the browser. It is possible the nodes returned are not linked and therefore not shown as being linked ...

Run this ...

MATCH (n)--(m) RETURN n,m

sucheta
Graph Buddy

Hi Paul,

I tried your query - >MATCH (n)--(m) RETURN n,m

output is -

But then i tried this query --> MATCH (n) -[r]-(m) RETURN n,r,m
Check here output with all nodes -
2X_0_016c38beeedb9a16b511586aa51f6b9b90699477.png

Is it okay i used this query --> MATCH (n) -[r]-(m) RETURN n,r,m.

Aren't the two outputs same ?

sucheta
Graph Buddy

Thanks paul for quick assistance.

I checked this option --> Connect result nodes

Now your query --> MATCH (n)--(m) RETURN n,m is showing all the nodes.

Thanks
Sucheta

sucheta
Graph Buddy

Paul,

I have a difficulty.
My application uploads a file , and that file uploads the data in Neo4j database. In my Neo4j Application, i already have a database present and the file uploaded also makes its entries in the same database.

So when i do --> Match (n) Return n; --> i get all the data network of both the root nodes.

So to obtain a single network , i did -
[1]
MATCH (n:Organization) RETURN n; --> ( as Organization is the root node of that uploaded file data)

output - Is only the Organisation single node.

[2]
And with this query --> MATCH (n:Organization)-[r]-(m) RETURN n,r,m

The result is just this much ->

Please help me retrieve a query that just gives one network out of the many

MATCH pathx=(n:Organization)-[*1..3]-(m) RETURN pathx

this will give you all nodes up to 3 hops from the starting node ...