Neo4j cypher query simulate sql join query - neo4j

I have two different kinds of node entities without any relationships between them, i wonder how to write a cypher query to join these two node entities by common property?
For example, if i want to return a blog by passing blogId as a parameter, but i also want to return creator username by joining user entity. Is it possible? Thanks in advance.

Why don't you have a relationship between user and blog? As far as graph dbs are concerned to connect data, this will help you to get users' blogs. Further, you can connect the blogs according to their topics etc.

Related

Using Cypher can I find a specific relationship between 2 distant nodes

I have 2 nodes not directly related to one another I know the start node, the end node and the relationship on the end node. For example
(u:USER)-[]->()-[]->()-[:WRITE]->(p:POST)
Is there a query I can write that would return 'p' to me? Also all the relationship in between are not WRITE, so I can't use [:WRITE*]
Secondary question: I'm thinking about permissions and relationships. In my model the User has a relationship on some entity and that entity to another all the way to a WRITE relationship on POST, and I want to therefore say the USER has WRITE on POST. But maybe I'm thinking about this wrong? Maybe I should just be giving USER WRITE on POST directly?
Thank you!
One of the great advantages of Neo4j over relational databases is that you don't have to know the labels of nodes or how they are related to perform a useful query.
If you try
(u:User)-[*]->()-[:WRITE]->(p:Post) return p
it should give you what you want.
The structure of your graph will determine the efficiency of this query. If the graph between :USER and :POST is essentially a tree, then the above query should be quite efficient. However, if the intervening nodes and relationships form a network, then the query could spend significant time exploring all paths between :User and :Post in which case your idea of linking :User to :Post via a single relationship would be beneficial.

Developing graph database model for department/supplier/items

I'm currently ramping up on graph databases and to do that am working through a set of questions to learn Cypher. However, I'm not 100% happy with the design I've chosen since I have to match relationships to nodes to make some of the queries work.
I found Neo4j: Suggestions for ways to model a graph with shared nodes but has a unique path based on some property with some suggestions that are relevant, but they involve copying nodes (repeating them) when in fact they do represent the same thing. That seems like an update issue waiting to happen.
My design currently has
(:Dept {name,floor})-[:SOLD {quantity}]->(:Item {name,type})<-[:SUPPLIES {dept,volume)]-(:Company {name,address})
As you can see, to figure out which department a company supplied an item to, I have to check the :SUPPLIES dept property. This leads to somewhat awkward queries - it feels that way to me, anyway.
I've tried other relationships, like having (:Company)-[:SUPPLIES {item,vol}]->(:Dept) but then the problem just shifts to matching :SUPPLIES relationship properties to :Item nodes.
The types of queries I am building are of the nature: Find departments that sell all of the items they are supplied.
Is there some other way to model this that I am overlooking? Or is this sort of relationship, where a supplier is related to two things, an item and a department, just something that doesn't fit the graph model very well?
You want to store and query a triangular relationship between :Dept, :Item, and :Company. This can't be accomplished by a linear relationship pattern. Comparing IDs of entities is not the Neo4j way, you would neglect the strengths of a graph database.
(Assuming that I understood your use case scenario) I would introduce an additional node of type :SupplyEvent that has relationships to :Dept, :Item, and :Company. You could also split up :SOLD relationship in a similar way, if you want relations between department, item, and, e.g., a customer.
Now, you can query all companies that supplied which items to which departments (without comparing any IDs):
MATCH (company:Company)<-[:SUPPLIED_FROM]-(se:SupplyEvent)-[:SUPPLIED_TO]->(dept:Dept),
(se)-[:SUPPLIED]->(item:Item)
RETURN company, item, dept

better approach to load referential data

I have entities related to cities in my Neo4j graph. I've created a form in which a user can create an entity, let's say a shop. In this form, I would like the user to choose the city of the shop from a combo box. I'm wondering what is the best approach : get all the cities from the graph with a cypher query or have all the cities (and other referential data) in another database (relational or nosql or whatever), and then populate my comboboxes ? Or is there a better approach ?
Thanks for your time,
Didier
I've just heard of polyglot persistence and read some articles. Should it be, in my case, the best approach to store cities and shops in a document database and then use my graph database to add relationships with customers, shops and cities?

Join Case and User in Salesforce (SOQL)

I'm used to PostgreSQL but very new to SOQL and a bit confused about it. I would like to join rows from Case with rows from User based on User.Id.
I've looked online and tried various solutions but nothing worked out.
Does anyone know I could do that? What type of relationship binds Case and User? Do I have to build a custom relationship between them?
Thanks
SOQL supports joins by following the relationship from the FK (using the relationship name), many of the schema explorer tools (SoqlX, Workbench, etc) will help you discover these and build/test SOQL queries.
In this case you want something like
select CaseNumber, LastModifiedBy.Name from Case Where ....
Try this, https://salesforce.stackexchange.com/questions/20572/soql-join-between-two-standard-objects
Select CaseNumber, LastModifiedById, (Select name From User)
From Case WHERE day_only(convertTimezone(ClosedDate))=TODAY

Relations to relation neo4j

Maybe it is a long shot but worth trying...
I have the following relation User1-[:MATCHED]-User2, I want to allow other users to give feedback (Like) on that relation, I am guessing that the obvious answer is to define new node from type Match which will be created for every two matched users and then relate to that node with LIKE relation from each user who liked the match.
I am trying to think about other way to model that in the graph without the overhead of creating new node for each match...
Can a relation relate to other nodes except the start/end nodes?
Any help will be appreciated thanks.
Neo4j does not support hypergraphs or relationships to relationships. Modelling your MATCHED relationship with a node is probably the way to go.
An alternative is to reference the relationship id from another node:
User1-[MATCHED]->User2 (where MATCHED has the id xyz)
User3-[LIKES]->Relationship(relId = xyz)
The "Relationship" node would contain the id of the MATCHED relationship as a property. This relId property would need to be indexed to find all LIKES of a given MATCHED relationship.
This solution is not well suited for traversals though.

Resources