Reputation: 353
I'm manipulating a document collection and an edge collection, and I want to perform a join operation to get details from the document collection.
Here is what I'm trying to do:
first: select from l2 where p = "568700933"
the join attribute in the other collection has as a value p = 568700933;
Second select Entry from P where reference = p+";"
and third return the Entry and p .
I have no clue how to join this
When I try select from a , b
I get an error
What I need is:
Select from edge node of key p = "568700933" , get the assosiated details from the document collection of the same key , knowing that the document collection had p = "568700933;"
Upvotes: 0
Views: 257
Reputation: 2814
There is no JOIN in OrientDB, you just cannot do it. Queries accept only a single target.
In a graph database, you define relationships as edges, not as pk/fk and join.
Once you have your edges, you can use SELECT with out()/in()
functions or MATCH to traverse them (http://orientdb.com/docs/2.2.x/SQL-Match.html)
[edit] here is a practical example on how to do this with OrientDB.
Suppose you have two vertex classes ClassP
and ClassQ
and and edge class called ClassE
First of all let's create the schema:
CREATE CLASS ClassP EXTENDS V;
CREATE CLASS ClassQ EXTENDS V;
CREATE CLASS ClassE EXTENDS E;
Now let's populate it with some data:
CREATE VERTEX ClassP SET name = 'foo';
CREATE VERTEX ClassP SET name = 'bar';
CREATE VERTEX ClassP SET id = 1;
CREATE VERTEX ClassP SET id = 2;
And connect them through edges:
/* from "foo" to "1" */
CREATE EDGE ClassE
FROM
(SELECT FROM ClassP WHERE name = 'foo')
TO
(SELECT FROM ClassQ WHERE id = 1)
SET myEdgeProp = 'x';
/* from "foo" to "2" */
CREATE EDGE ClassE
FROM
(SELECT FROM ClassP WHERE name = 'foo')
TO
(SELECT FROM ClassQ WHERE id = 2)
SET myEdgeProp = 'y';
/* from "bar" to "2" */
CREATE EDGE ClassE
FROM
(SELECT FROM ClassP WHERE name = 'bar')
TO
(SELECT FROM ClassQ WHERE id = 2)
SET myEdgeProp = 'z';
Now we can query the dataset as follows:
/* get the name of a vertex and all the connected IDs */
SELECT name, out("ClassE").id FROM ClassP WHERE name = 'foo';
or
MATCH
{class:ClassP, as:a, where:(name = 'foo')} -ClassE-> {as:b}
RETURN a.name as name, b.id as id
or
/* return all the details for all the vertices */
MATCH
{class:ClassP, as:a, where:(name = 'foo')} -ClassE-> {as:b}
RETURN $elements
I hope it helps
Upvotes: 1