SlideShare a Scribd company logo
Neo4j
Introduction &
Slip Solving
Sessions
Dr. Dipali Meher
MCS, M.Phil, NET, Ph.D
PES Modern College of Arts, Science and Commerce, Ganeshkhind , Pune 16
dipalimeher@moderncollegegk.org
Agenda
Introduction
Using Online Console/Sandbox
Creation of Nodes
Creation of Relationships
Firing Cypher Queries
2
Prepared by - Dr. Dipali Meher
ā€˜ā€™
Introduction
3
Prepared by - Dr. Dipali Meher
ā€˜ā€™
4
Prepared by - Dr. Dipali Meher
5
Prepared by - Dr. Dipali Meher
6
Use of graphs has created some of the most successful
companies in the world
7
Prepared by - Dr. Dipali Meher
8
Prepared by - Dr. Dipali Meher
9
Prepared by - Dr. Dipali Meher
10
Prepared by - Dr. Dipali Meher
11
Prepared by - Dr. Dipali Meher
12
Prepared by - Dr. Dipali Meher
13
Prepared by - Dr. Dipali Meher
14
Prepared by - Dr. Dipali Meher
15
Prepared by - Dr. Dipali Meher
Why Graphs DBS?
ā–£ Intuitiveness
ā–£ Speed
ā–£ Agility
16
Prepared by - Dr. Dipali Meher
17
Prepared by - Dr. Dipali Meher
Using Online Console/Sandbox
ā–£ https://console.neo4j.org/
ā–£ https://neo4j.com/sandbox/
18
Prepared by - Dr. Dipali Meher
Creation of Nodes
ā–£ To create single node with label with properties
ā–£ create(alis:node name)
ā–£ E.g. create(p:person{name:"Dipali", add:ā€œPuneā€œ})
ā–£ To create multiple nodes
ā–£ create(alis:node name) Create(alies:node name)
ā–£ create(p:person{name:"Dipali", add:ā€œPuneā€œ})
ā–£ create(p:person{name:ā€œShreya", add:ā€œPuneā€œ})
ā–£ To see the result always write return statement which is same as select in
SQL
19
Prepared by - Dr. Dipali Meher
Creation of Relationships
ā–£ Match: The MATCH clause allows you to specify the patterns Neo4j will
search for in the database.
ā–£ Syntax:
ā–£ MATCH (a:node1), (b:node2) WHERE match the conditions
ā–£ CREATE (a)-[r:RELTYPE]->(b) RETURN type(r)
ā–£ example
ā–£ MATCH (a:Person), (b:Person) WHERE a.name = ā€˜Dipali' AND b.name = ā€˜Shreya' CREATE (a)-
[r:motherof]->(b) RETURN a,b
20
Prepared by - Dr. Dipali Meher
Firing Cypher Queries
ā–£ With match keyword
ā–£ Using the MATCH clause of Neo4j you can
retrieve all nodes in the Neo4j database.
MATCH (node:label) RETURN node
21
Prepared by - Dr. Dipali Meher
Slip: Person
Model the following Society relations among people
working in ā€œHCLā€, as a graph model, and answer the
queries using Cypher.
A person can be a friend of another person. A person
may have siblings (brothers / sisters), A person may be a
parent(mother/father) of another person. A person stays
either in Pune or Mumbai or Kolhapur. A person may be
working on either ā€˜Finance’ or ā€˜Inventory’ or ā€˜Sales’
projects.
22 Prepared by - Dr. Dipali Meher
Person Person
Person
Person
Person
Person
Name:Dipali
Name:Meenal
Name:Prakash
Name:Omkar
Name:Kaustubh
Name:Pallawi
Name:Mrunu
Name:Rugved
Person
Person
Person
City
Friend of
Sister of
Brother of
Sister of
City
City
Name:Kolhapur
Name:Mumbai
Name:Pune
Project
Project
Project
workson
Name:Finance Name: Inventory
Name: Sales
23
Prepared by - Dr. Dipali Meher
Node Creation: Person
ā–£ create(p:Person{name:"Dipali",age:39}) return p
ā–£ create(p:Person{name:"Pallawi",age:43}) return p
ā–£ create(p:Person{name:"Meenal",age:38}) return p
ā–£ create(p:Person{name:"Prakash",age:40}) return p
ā–£ create(p:Person{name:"Mrunu",age:20}) return p
ā–£ create(p:Person{name:"Rugved",age:40}) return p
ā–£ create(p:Person{name:"Shreya",age:20}) return p
ā–£ create(p:Person{name:"Omkar",age:40}) return p
ā–£ create(p:Person{name:"Kaustubh",age:45}) return p
24
Prepared by - Dr. Dipali Meher
Relationship Creation: Friend
ā–£ match(p:Person),(pp:Person)
where p.name="Dipali" and pp.name="Pallawi"
create(p)-[:Friend_of]->(pp)
return p,pp
ā–£ match(p:Person),(pp:Person)
where p.name="Dipali" and pp.name="Meenal"
create(p)-[:Friend_of]->(pp)
return p,pp
25
Prepared by - Dr. Dipali Meher
Relationship Creation: siblings(brother/sister)
ā–£ match(p:Person),(pp:Person) where p.name="Mrunu" and
pp.name="Rugved" create(p)-[:sisterof]->(pp)return p,pp
ā–£ match(p:Person),(pp:Person) where p.name="Omkar" and
pp.name="Shreya" create(p)-[:brotherof]->(pp)return p,pp
ā–£ match(p:Person),(pp:Person) where p.name="Meenal" and
pp.name="Mrunu" create(p)-[:motherof]->(pp)return p,pp
ā–£ match(p:Person),(pp:Person) where p.name="Meenal" and
pp.name="Rugved" create(p)-[:motherof]->(pp)return p,pp
ā–£
26
Prepared by - Dr. Dipali Meher
Relationship Creation: Parents(father/mother)
ā–£ match(p:Person),(pp:Person) where p.name="Kaustubh" and
pp.name="Mrunu" create(p)-[:fatherof]->(pp)return p,pp
ā–£ match(p:Person),(pp:Person) where p.name="Kaustubh" and
pp.name="Rugved" create(p)-[:fatherof]->(pp)return p,pp
ā–£ match(p:Person),(pp:Person) where p.name="Dipali" and
pp.name="Shreya" create(p)-[:motherof]->(pp)return p,pp
ā–£ match(p:Person),(pp:Person) where p.name="Prakash" and
pp.name="Shreya" create(p)-[:fatherof]->(pp)return p,pp
27
Prepared by - Dr. Dipali Meher
Node Creation: City
ā–£ create(c:City{name:"Pune"}) return c
ā–£ create(c:City{name:"Mumbai"}) return c
ā–£ create(c:City{name:"Kolhapur"}) return c
28
Prepared by - Dr. Dipali Meher
Relationship Creation: staysin
ā–£ match(p:Person),(c:City) where p.name="Prakash" and
c.name="Pune" create(p)-[:staysin]->(c)return p,c
ā–£ match(p:Person),(c:City) where p.name="Kaustubh" and
c.name="Mumbai" create(p)-[:staysin]->(c)return p,c
ā–£ match(p:Person),(c:City) where p.name="Meenal" and
c.name="Mumbai" create(p)-[:staysin]->(c)return p,c
ā–£ match(p:Person),(c:City) where p.name="Dipali" and
c.name="Pune" create(p)-[:staysin]->(c)return p,c
29
Prepared by - Dr. Dipali Meher
Node Creation: Project
ā–£ create(pr:Project{name:"Finance"}) return pr
ā–£ create(pr:Project{name:"Inventory"}) return pr
ā–£ create(pr:Project{name:"Sales"}) return pr
30
Prepared by - Dr. Dipali Meher
Relationship Creation:Workson
ā–£ match(p:Person),(pr:Project) where p.name="Prakash" and
pr.name="Finance" create(p)-[:workson]->(pr)
return p,pr
ā–£ match(p:Person),(pr:Project) where p.name="Kaustubh" and
pr.name="Inventory" create(p)-[:workson]->(pr)
return p,pr
ā–£ match(p:Person),(pr:Project) where p.name="Dipali" and
pr.name="Sales" create(p)-[:workson]->(pr)
return p,pr
31
Prepared by - Dr. Dipali Meher
Queries
List the names of people who are parents
MATCH (p:Person),(pp:Person) Where
(p)-[:fatherof]->(pp)
RETURN DISTINCT p.name AS name1
UNION ALL
MATCH (p:Person),(pp:Person)
Where
(p)-[:motherof]->(pp)
RETURN DISTINCT p.name AS name1
32
Prepared by - Dr. Dipali Meher
Queries
List the names of people working on ā€˜Finance ā€˜project
match(p:Person),(pr:Project)
where
pr.name="Finance" and(p)-[:workson]->(pr)
return p.name
33
Prepared by - Dr. Dipali Meher
Queries
List the names of people staying in ā€˜Pune’ and ā€˜Mumbai’.
MATCH (p:Person),(c:City)
WHERE c.name IN ['Pune', 'Mumbai']
and
(p)-[:staysin]->(c)
RETURN p.name
34
Prepared by - Dr. Dipali Meher
Queries
List the names of people who are mothers.
match(p:Person),(pp:Person)
where
(p)-[:motherof]->(pp)
return DISTINCT p.name
35
Prepared by - Dr. Dipali Meher
Queries
Display the names of people living in Mumbai.
match(p:Person),(c:City)
where c.name="Mumbai"
and (p)-[:staysin]->(c)
return p.name
Display the nodes having age above 40.
match(p:Person)
where p.age>40
return p.name
36
Prepared by - Dr. Dipali Meher
Slip :University
Model the following University information
system as a graph model, and answer the
following queries using Cypher.
University has various departments like
Mathematics, Geology, Chemistry, etc. Each
department conducts various courses and a
course may be conducted by multiple
departments. Every course may have
recommendations provided by people.
37 Prepared by - Dr. Dipali Meher
Node Creation:
ā–£ create(:University{name:'SPPU',location:'Pune'})
Department Creation
ā–£ create (:Department{name:'Comp-Sci'})
ā–£ create (:Department{name:'Zoology'})
ā–£ create (:Department{name:'Maths'})
ā–£ create (:Department{name:'Chemistry'})
ā–£
38
Prepared by - Dr. Dipali Meher
Relationship Creation: has
ā–£ match(u:University),(d:Department) where u.name='SPPU'and
d.name='Zoology' create (u)-[:Has]->(d) return u,d
ā–£ match(u:University),(d:Department) where u.name='SPPU'and
d.name='Chemistry' create (u)-[:Has]->(d) return u,d
ā–£ match(u:University),(d:Department) where u.name='SPPU'and
d.name='Maths' create (u)-[:Has]->(d) return u,d
ā–£ match(u:University),(d:Department) where u.name='SPPU'and
d.name='Comp-Sci' create (u)-[:Has]->(d) return u,d
ā–£
39
Prepared by - Dr. Dipali Meher
Node Creation: Course
ā–£ create (:Course{name:'ExtraCredit'})
ā–£ create (:Course{name:'BBA'})
ā–£ create (:Course{name:'Analytical'})
ā–£ create (:Course{name:'Fish culture'})
40
Prepared by - Dr. Dipali Meher
Relationship creation: conducts
ā–£ match(c:Course),(d:Department) where d.name='Comp-Sci' and
c.name='BBA' create (d)-[:Conducts]->(c) return d,c
ā–£ match(c:Course),(d:Department) where d.name='Maths' and
c.name='BBA' create (d)-[:Conducts]->(c) return d,c
ā–£ match(c:Course),(d:Department) where d.name='Maths' and
c.name='ExtraCredit' create (d)-[:Conducts]->(c) return d,c
ā–£ match(c:Course),(d:Department) where d.name='Zoology' and
c.name='ExtraCredit' create (d)-[:Conducts]->(c) return d,c
ā–£ match(c:Course),(d:Department) where d.name='Chemistry' and
c.name='ExtraCredit' create (d)-[:Conducts]->(c) return d,c
41
Prepared by - Dr. Dipali Meher
Node Creation: People
ā–£ create (:People{name:'Dipali'})
ā–£ create (:People{name:'Maharaj'})
ā–£ create (:People{name:'Datta'})
42
Prepared by - Dr. Dipali Meher
Relationship Creation: recommands
ā–£ MATCH (p:People), (c:Course) WHERE p.name = "Datta" AND
c.name = "ExtraCredit" CREATE (p)-[:recommands ]->(c) RETURN p,c
ā–£ MATCH (p:People), (c:Course) WHERE p.name = "Maharaj" AND
c.name = "ExtraCredit" CREATE (p)-[:recommands ]->(c) RETURN p,c
ā–£ MATCH (p:People), (c:Course) WHERE p.name = "Dipali" AND
c.name = "ExtraCredit" CREATE (p)-[:recommands ]->(c) RETURN p,c
ā–£ MATCH (p:People), (c:Course) WHERE p.name = "Dipali" AND
c.name = "BBA" CREATE (p)-[:recommands ]->(c) RETURN p,c
43
Prepared by - Dr. Dipali Meher
Queries
ā–£ List the details of all the departments in the
university
match(u:University),(d:Department)
where
u.name='SPPU' and (d)-[:Conducts]->(c)
return d.name
44
Prepared by - Dr. Dipali Meher
Queries
List the names of common courses across computer Science
and Maths department.
WITH ['Comp-Sci','Maths'] as names
MATCH (d:Department) WHERE
d.name in names WITH collect(d) as s
MATCH (c:Course)
WHERE ALL(d in s WHERE (d)-[:Conducts]->(c))
RETURN c
45
Prepared by - Dr. Dipali Meher
Queries
ā–£ List the courses run by chemistry department
match(c:Course),(d:Department)
where d.name='Chemistry' and
(d)-[:Conducts]->(c) return d,c,c.name
46
Prepared by - Dr. Dipali Meher
Queries
ā–£ List the most recommended course in Zoology Department.
MATCH (p:People)-[:recommands]->(c:Course),
(d:Department)-[:Conducts]->(c:Course)
where d.name="Zoology" with c.name as names,
count(c.name) as count_vt WITH collect({names:names, count_vt:count_vt})
as rows, max(count_vt) as max
UNWIND [row in rows WHERE row.count_vt = max] as row
RETURN row.names as names, row.count_vt as count_vt
47
Prepared by - Dr. Dipali Meher
ā–£ UNWIND : With UNWIND , you can transform any list back into individual
rows.
ā–£ With : Using WITH, you can manipulate the output before it is passed on to
the following query parts. The manipulations can be of the shape and/or
number of entries in the result set. One common usage of WITH is to limit
the number of entries that are then passed on to other MATCH clauses.
WITH is used to introduce aggregates which can then be used in predicates
in WHERE
ā–£ Collect: The function collect() returns a single aggregated list containing the
values returned by an expression.
48
Prepared by - Dr. Dipali Meher
References
ā–£ https://www.slideshare.net/neo4j/intro-to-neo4j
ā–£ https://www.slideshare.net/neo4j/introduction-to-neo4j-120324228
ā–£ https://www.slideshare.net/neo4j/intro-to-neo4j-and-graph-databases
ā–£ https://neo4j.com
49
Prepared by - Dr. Dipali Meher
Thanks
Any questions?
You can find me at
dipalimeher@moderncollegegk.org
50

More Related Content

PPTX
Polyglot Persistence
PPTX
Schema migrations in no sql
PPTX
Introduction to NOSQL databases
PPT
5 Data Modeling for NoSQL 1/2
PPTX
Non relational databases-no sql
PPTX
Introduction to NoSQL
PPT
7. Key-Value Databases: In Depth
PPTX
Key-Value NoSQL Database
Polyglot Persistence
Schema migrations in no sql
Introduction to NOSQL databases
5 Data Modeling for NoSQL 1/2
Non relational databases-no sql
Introduction to NoSQL
7. Key-Value Databases: In Depth
Key-Value NoSQL Database

What's hot (20)

PDF
Nosql data models
PPTX
Chapter 7.pptx
PPTX
Chapter 3.pptx
PPTX
PPTX
Paradigms of Programming Languages CH1-Introduction.pptx
PPTX
Introduction to NoSQL Databases
PPTX
Introduction to NoSQL
PPTX
Mongodb basics and architecture
PPTX
Introduction to Apache ZooKeeper
PPTX
Nosql databases
PPTX
NOSQL Databases types and Uses
PPTX
Hadoop File system (HDFS)
PPTX
Introduction to Apache Spark
PDF
PPTX
Chapter 5.pptx
PDF
NoSQL databases
PDF
MySQL: Indexing for Better Performance
PDF
Oracle db performance tuning
PPTX
RDBMS
PDF
Introduction of MariaDB 2017 09
Nosql data models
Chapter 7.pptx
Chapter 3.pptx
Paradigms of Programming Languages CH1-Introduction.pptx
Introduction to NoSQL Databases
Introduction to NoSQL
Mongodb basics and architecture
Introduction to Apache ZooKeeper
Nosql databases
NOSQL Databases types and Uses
Hadoop File system (HDFS)
Introduction to Apache Spark
Chapter 5.pptx
NoSQL databases
MySQL: Indexing for Better Performance
Oracle db performance tuning
RDBMS
Introduction of MariaDB 2017 09
Ad

Similar to Neo4j session (20)

PPT
Neo4 j
PDF
Data modeling with neo4j tutorial
PPTX
The Inside Scoop on Neo4j: Meet the Builders
Ā 
PPTX
Graph Database workshop
PDF
Training Week: Introduction to Neo4j
Ā 
PDF
New opportunities for connected data
Ā 
PDF
Building Applications with a Graph Database
PDF
Neo4j Introduction (Basics, Cypher, RDBMS to GRAPH)
PDF
Neo4j Graph Data Science Training - June 9 & 10 - Slides #3
Ā 
PDF
Introduction to Neo4j - a hands-on crash course
Ā 
PDF
20141216 graph database prototyping ams meetup
PPTX
Neo4j.pptx
PDF
RadioBOSS Advanced 7.0.8 Free Download
PDF
Evernote 10.132.4.49891 With Crack free
PDF
Roadmap y Novedades de producto
Ā 
PDF
Adobe Photoshop 2025 Free crack Download
PDF
Office Tool Plus Free Download (Latest 2025)
PDF
Graph Database Using Neo4J
PDF
Neo4J
Neo4 j
Data modeling with neo4j tutorial
The Inside Scoop on Neo4j: Meet the Builders
Ā 
Graph Database workshop
Training Week: Introduction to Neo4j
Ā 
New opportunities for connected data
Ā 
Building Applications with a Graph Database
Neo4j Introduction (Basics, Cypher, RDBMS to GRAPH)
Neo4j Graph Data Science Training - June 9 & 10 - Slides #3
Ā 
Introduction to Neo4j - a hands-on crash course
Ā 
20141216 graph database prototyping ams meetup
Neo4j.pptx
RadioBOSS Advanced 7.0.8 Free Download
Evernote 10.132.4.49891 With Crack free
Roadmap y Novedades de producto
Ā 
Adobe Photoshop 2025 Free crack Download
Office Tool Plus Free Download (Latest 2025)
Graph Database Using Neo4J
Neo4J
Ad

More from Dr-Dipali Meher (14)

PPTX
Database Security Methods, DAC, MAC,View
PPTX
Version Stamps in NOSQL Databases
PPTX
DataPreprocessing.pptx
PPTX
Literature Review
PPTX
Research Problem
PPTX
Formulation of Research Design
PPTX
Types of Research
PPTX
Research Methodology-Intorduction
PPTX
Introduction to Research
PPTX
Consistency in NoSQL
PPTX
Data models in NoSQL
PPTX
Naive bayesian classification
PPTX
Data mining an introduction
PPTX
Function Pointer
Database Security Methods, DAC, MAC,View
Version Stamps in NOSQL Databases
DataPreprocessing.pptx
Literature Review
Research Problem
Formulation of Research Design
Types of Research
Research Methodology-Intorduction
Introduction to Research
Consistency in NoSQL
Data models in NoSQL
Naive bayesian classification
Data mining an introduction
Function Pointer

Recently uploaded (20)

PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
Updated Idioms and Phrasal Verbs in English subject
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PDF
Trump Administration's workforce development strategy
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
Weekly quiz Compilation Jan -July 25.pdf
PPTX
Cell Structure & Organelles in detailed.
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PDF
Yogi Goddess Pres Conference Studio Updates
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PPTX
History, Philosophy and sociology of education (1).pptx
Ā 
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Lesson notes of climatology university.
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Final Presentation General Medicine 03-08-2024.pptx
Microbial disease of the cardiovascular and lymphatic systems
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
Updated Idioms and Phrasal Verbs in English subject
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Orientation - ARALprogram of Deped to the Parents.pptx
Trump Administration's workforce development strategy
A systematic review of self-coping strategies used by university students to ...
Weekly quiz Compilation Jan -July 25.pdf
Cell Structure & Organelles in detailed.
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
Yogi Goddess Pres Conference Studio Updates
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
History, Philosophy and sociology of education (1).pptx
Ā 
01-Introduction-to-Information-Management.pdf
Lesson notes of climatology university.

Neo4j session

  • 1. Neo4j Introduction & Slip Solving Sessions Dr. Dipali Meher MCS, M.Phil, NET, Ph.D PES Modern College of Arts, Science and Commerce, Ganeshkhind , Pune 16 dipalimeher@moderncollegegk.org
  • 2. Agenda Introduction Using Online Console/Sandbox Creation of Nodes Creation of Relationships Firing Cypher Queries 2 Prepared by - Dr. Dipali Meher
  • 4. ā€˜ā€™ 4 Prepared by - Dr. Dipali Meher
  • 5. 5 Prepared by - Dr. Dipali Meher
  • 6. 6
  • 7. Use of graphs has created some of the most successful companies in the world 7 Prepared by - Dr. Dipali Meher
  • 8. 8 Prepared by - Dr. Dipali Meher
  • 9. 9 Prepared by - Dr. Dipali Meher
  • 10. 10 Prepared by - Dr. Dipali Meher
  • 11. 11 Prepared by - Dr. Dipali Meher
  • 12. 12 Prepared by - Dr. Dipali Meher
  • 13. 13 Prepared by - Dr. Dipali Meher
  • 14. 14 Prepared by - Dr. Dipali Meher
  • 15. 15 Prepared by - Dr. Dipali Meher
  • 16. Why Graphs DBS? ā–£ Intuitiveness ā–£ Speed ā–£ Agility 16 Prepared by - Dr. Dipali Meher
  • 17. 17 Prepared by - Dr. Dipali Meher
  • 18. Using Online Console/Sandbox ā–£ https://console.neo4j.org/ ā–£ https://neo4j.com/sandbox/ 18 Prepared by - Dr. Dipali Meher
  • 19. Creation of Nodes ā–£ To create single node with label with properties ā–£ create(alis:node name) ā–£ E.g. create(p:person{name:"Dipali", add:ā€œPuneā€œ}) ā–£ To create multiple nodes ā–£ create(alis:node name) Create(alies:node name) ā–£ create(p:person{name:"Dipali", add:ā€œPuneā€œ}) ā–£ create(p:person{name:ā€œShreya", add:ā€œPuneā€œ}) ā–£ To see the result always write return statement which is same as select in SQL 19 Prepared by - Dr. Dipali Meher
  • 20. Creation of Relationships ā–£ Match: The MATCH clause allows you to specify the patterns Neo4j will search for in the database. ā–£ Syntax: ā–£ MATCH (a:node1), (b:node2) WHERE match the conditions ā–£ CREATE (a)-[r:RELTYPE]->(b) RETURN type(r) ā–£ example ā–£ MATCH (a:Person), (b:Person) WHERE a.name = ā€˜Dipali' AND b.name = ā€˜Shreya' CREATE (a)- [r:motherof]->(b) RETURN a,b 20 Prepared by - Dr. Dipali Meher
  • 21. Firing Cypher Queries ā–£ With match keyword ā–£ Using the MATCH clause of Neo4j you can retrieve all nodes in the Neo4j database. MATCH (node:label) RETURN node 21 Prepared by - Dr. Dipali Meher
  • 22. Slip: Person Model the following Society relations among people working in ā€œHCLā€, as a graph model, and answer the queries using Cypher. A person can be a friend of another person. A person may have siblings (brothers / sisters), A person may be a parent(mother/father) of another person. A person stays either in Pune or Mumbai or Kolhapur. A person may be working on either ā€˜Finance’ or ā€˜Inventory’ or ā€˜Sales’ projects. 22 Prepared by - Dr. Dipali Meher
  • 23. Person Person Person Person Person Person Name:Dipali Name:Meenal Name:Prakash Name:Omkar Name:Kaustubh Name:Pallawi Name:Mrunu Name:Rugved Person Person Person City Friend of Sister of Brother of Sister of City City Name:Kolhapur Name:Mumbai Name:Pune Project Project Project workson Name:Finance Name: Inventory Name: Sales 23 Prepared by - Dr. Dipali Meher
  • 24. Node Creation: Person ā–£ create(p:Person{name:"Dipali",age:39}) return p ā–£ create(p:Person{name:"Pallawi",age:43}) return p ā–£ create(p:Person{name:"Meenal",age:38}) return p ā–£ create(p:Person{name:"Prakash",age:40}) return p ā–£ create(p:Person{name:"Mrunu",age:20}) return p ā–£ create(p:Person{name:"Rugved",age:40}) return p ā–£ create(p:Person{name:"Shreya",age:20}) return p ā–£ create(p:Person{name:"Omkar",age:40}) return p ā–£ create(p:Person{name:"Kaustubh",age:45}) return p 24 Prepared by - Dr. Dipali Meher
  • 25. Relationship Creation: Friend ā–£ match(p:Person),(pp:Person) where p.name="Dipali" and pp.name="Pallawi" create(p)-[:Friend_of]->(pp) return p,pp ā–£ match(p:Person),(pp:Person) where p.name="Dipali" and pp.name="Meenal" create(p)-[:Friend_of]->(pp) return p,pp 25 Prepared by - Dr. Dipali Meher
  • 26. Relationship Creation: siblings(brother/sister) ā–£ match(p:Person),(pp:Person) where p.name="Mrunu" and pp.name="Rugved" create(p)-[:sisterof]->(pp)return p,pp ā–£ match(p:Person),(pp:Person) where p.name="Omkar" and pp.name="Shreya" create(p)-[:brotherof]->(pp)return p,pp ā–£ match(p:Person),(pp:Person) where p.name="Meenal" and pp.name="Mrunu" create(p)-[:motherof]->(pp)return p,pp ā–£ match(p:Person),(pp:Person) where p.name="Meenal" and pp.name="Rugved" create(p)-[:motherof]->(pp)return p,pp ā–£ 26 Prepared by - Dr. Dipali Meher
  • 27. Relationship Creation: Parents(father/mother) ā–£ match(p:Person),(pp:Person) where p.name="Kaustubh" and pp.name="Mrunu" create(p)-[:fatherof]->(pp)return p,pp ā–£ match(p:Person),(pp:Person) where p.name="Kaustubh" and pp.name="Rugved" create(p)-[:fatherof]->(pp)return p,pp ā–£ match(p:Person),(pp:Person) where p.name="Dipali" and pp.name="Shreya" create(p)-[:motherof]->(pp)return p,pp ā–£ match(p:Person),(pp:Person) where p.name="Prakash" and pp.name="Shreya" create(p)-[:fatherof]->(pp)return p,pp 27 Prepared by - Dr. Dipali Meher
  • 28. Node Creation: City ā–£ create(c:City{name:"Pune"}) return c ā–£ create(c:City{name:"Mumbai"}) return c ā–£ create(c:City{name:"Kolhapur"}) return c 28 Prepared by - Dr. Dipali Meher
  • 29. Relationship Creation: staysin ā–£ match(p:Person),(c:City) where p.name="Prakash" and c.name="Pune" create(p)-[:staysin]->(c)return p,c ā–£ match(p:Person),(c:City) where p.name="Kaustubh" and c.name="Mumbai" create(p)-[:staysin]->(c)return p,c ā–£ match(p:Person),(c:City) where p.name="Meenal" and c.name="Mumbai" create(p)-[:staysin]->(c)return p,c ā–£ match(p:Person),(c:City) where p.name="Dipali" and c.name="Pune" create(p)-[:staysin]->(c)return p,c 29 Prepared by - Dr. Dipali Meher
  • 30. Node Creation: Project ā–£ create(pr:Project{name:"Finance"}) return pr ā–£ create(pr:Project{name:"Inventory"}) return pr ā–£ create(pr:Project{name:"Sales"}) return pr 30 Prepared by - Dr. Dipali Meher
  • 31. Relationship Creation:Workson ā–£ match(p:Person),(pr:Project) where p.name="Prakash" and pr.name="Finance" create(p)-[:workson]->(pr) return p,pr ā–£ match(p:Person),(pr:Project) where p.name="Kaustubh" and pr.name="Inventory" create(p)-[:workson]->(pr) return p,pr ā–£ match(p:Person),(pr:Project) where p.name="Dipali" and pr.name="Sales" create(p)-[:workson]->(pr) return p,pr 31 Prepared by - Dr. Dipali Meher
  • 32. Queries List the names of people who are parents MATCH (p:Person),(pp:Person) Where (p)-[:fatherof]->(pp) RETURN DISTINCT p.name AS name1 UNION ALL MATCH (p:Person),(pp:Person) Where (p)-[:motherof]->(pp) RETURN DISTINCT p.name AS name1 32 Prepared by - Dr. Dipali Meher
  • 33. Queries List the names of people working on ā€˜Finance ā€˜project match(p:Person),(pr:Project) where pr.name="Finance" and(p)-[:workson]->(pr) return p.name 33 Prepared by - Dr. Dipali Meher
  • 34. Queries List the names of people staying in ā€˜Pune’ and ā€˜Mumbai’. MATCH (p:Person),(c:City) WHERE c.name IN ['Pune', 'Mumbai'] and (p)-[:staysin]->(c) RETURN p.name 34 Prepared by - Dr. Dipali Meher
  • 35. Queries List the names of people who are mothers. match(p:Person),(pp:Person) where (p)-[:motherof]->(pp) return DISTINCT p.name 35 Prepared by - Dr. Dipali Meher
  • 36. Queries Display the names of people living in Mumbai. match(p:Person),(c:City) where c.name="Mumbai" and (p)-[:staysin]->(c) return p.name Display the nodes having age above 40. match(p:Person) where p.age>40 return p.name 36 Prepared by - Dr. Dipali Meher
  • 37. Slip :University Model the following University information system as a graph model, and answer the following queries using Cypher. University has various departments like Mathematics, Geology, Chemistry, etc. Each department conducts various courses and a course may be conducted by multiple departments. Every course may have recommendations provided by people. 37 Prepared by - Dr. Dipali Meher
  • 38. Node Creation: ā–£ create(:University{name:'SPPU',location:'Pune'}) Department Creation ā–£ create (:Department{name:'Comp-Sci'}) ā–£ create (:Department{name:'Zoology'}) ā–£ create (:Department{name:'Maths'}) ā–£ create (:Department{name:'Chemistry'}) ā–£ 38 Prepared by - Dr. Dipali Meher
  • 39. Relationship Creation: has ā–£ match(u:University),(d:Department) where u.name='SPPU'and d.name='Zoology' create (u)-[:Has]->(d) return u,d ā–£ match(u:University),(d:Department) where u.name='SPPU'and d.name='Chemistry' create (u)-[:Has]->(d) return u,d ā–£ match(u:University),(d:Department) where u.name='SPPU'and d.name='Maths' create (u)-[:Has]->(d) return u,d ā–£ match(u:University),(d:Department) where u.name='SPPU'and d.name='Comp-Sci' create (u)-[:Has]->(d) return u,d ā–£ 39 Prepared by - Dr. Dipali Meher
  • 40. Node Creation: Course ā–£ create (:Course{name:'ExtraCredit'}) ā–£ create (:Course{name:'BBA'}) ā–£ create (:Course{name:'Analytical'}) ā–£ create (:Course{name:'Fish culture'}) 40 Prepared by - Dr. Dipali Meher
  • 41. Relationship creation: conducts ā–£ match(c:Course),(d:Department) where d.name='Comp-Sci' and c.name='BBA' create (d)-[:Conducts]->(c) return d,c ā–£ match(c:Course),(d:Department) where d.name='Maths' and c.name='BBA' create (d)-[:Conducts]->(c) return d,c ā–£ match(c:Course),(d:Department) where d.name='Maths' and c.name='ExtraCredit' create (d)-[:Conducts]->(c) return d,c ā–£ match(c:Course),(d:Department) where d.name='Zoology' and c.name='ExtraCredit' create (d)-[:Conducts]->(c) return d,c ā–£ match(c:Course),(d:Department) where d.name='Chemistry' and c.name='ExtraCredit' create (d)-[:Conducts]->(c) return d,c 41 Prepared by - Dr. Dipali Meher
  • 42. Node Creation: People ā–£ create (:People{name:'Dipali'}) ā–£ create (:People{name:'Maharaj'}) ā–£ create (:People{name:'Datta'}) 42 Prepared by - Dr. Dipali Meher
  • 43. Relationship Creation: recommands ā–£ MATCH (p:People), (c:Course) WHERE p.name = "Datta" AND c.name = "ExtraCredit" CREATE (p)-[:recommands ]->(c) RETURN p,c ā–£ MATCH (p:People), (c:Course) WHERE p.name = "Maharaj" AND c.name = "ExtraCredit" CREATE (p)-[:recommands ]->(c) RETURN p,c ā–£ MATCH (p:People), (c:Course) WHERE p.name = "Dipali" AND c.name = "ExtraCredit" CREATE (p)-[:recommands ]->(c) RETURN p,c ā–£ MATCH (p:People), (c:Course) WHERE p.name = "Dipali" AND c.name = "BBA" CREATE (p)-[:recommands ]->(c) RETURN p,c 43 Prepared by - Dr. Dipali Meher
  • 44. Queries ā–£ List the details of all the departments in the university match(u:University),(d:Department) where u.name='SPPU' and (d)-[:Conducts]->(c) return d.name 44 Prepared by - Dr. Dipali Meher
  • 45. Queries List the names of common courses across computer Science and Maths department. WITH ['Comp-Sci','Maths'] as names MATCH (d:Department) WHERE d.name in names WITH collect(d) as s MATCH (c:Course) WHERE ALL(d in s WHERE (d)-[:Conducts]->(c)) RETURN c 45 Prepared by - Dr. Dipali Meher
  • 46. Queries ā–£ List the courses run by chemistry department match(c:Course),(d:Department) where d.name='Chemistry' and (d)-[:Conducts]->(c) return d,c,c.name 46 Prepared by - Dr. Dipali Meher
  • 47. Queries ā–£ List the most recommended course in Zoology Department. MATCH (p:People)-[:recommands]->(c:Course), (d:Department)-[:Conducts]->(c:Course) where d.name="Zoology" with c.name as names, count(c.name) as count_vt WITH collect({names:names, count_vt:count_vt}) as rows, max(count_vt) as max UNWIND [row in rows WHERE row.count_vt = max] as row RETURN row.names as names, row.count_vt as count_vt 47 Prepared by - Dr. Dipali Meher
  • 48. ā–£ UNWIND : With UNWIND , you can transform any list back into individual rows. ā–£ With : Using WITH, you can manipulate the output before it is passed on to the following query parts. The manipulations can be of the shape and/or number of entries in the result set. One common usage of WITH is to limit the number of entries that are then passed on to other MATCH clauses. WITH is used to introduce aggregates which can then be used in predicates in WHERE ā–£ Collect: The function collect() returns a single aggregated list containing the values returned by an expression. 48 Prepared by - Dr. Dipali Meher
  • 49. References ā–£ https://www.slideshare.net/neo4j/intro-to-neo4j ā–£ https://www.slideshare.net/neo4j/introduction-to-neo4j-120324228 ā–£ https://www.slideshare.net/neo4j/intro-to-neo4j-and-graph-databases ā–£ https://neo4j.com 49 Prepared by - Dr. Dipali Meher
  • 50. Thanks Any questions? You can find me at dipalimeher@moderncollegegk.org 50

Editor's Notes

  • #17: Intuitive:Ā having the ability to know or understand things without any proof or evidence AgilityĀ is defined as the ability to move nimbly with speed and ease.