0
votes

I have experimented with the documentation and the console but didn't find a way to do this.

Vertex with property "A",Vertex with property "B" and Edge with label "Connected".

I want to find out the edges that connect these two vertices and get the id's of the edges.

I haven't been able to do that getting the edges. I can do

select from (SELECT EXPAND(BOTH('Connected')) FROM Tag WHERE prop='A') where prop='B'

but I need to get the edge @rid. if I change BOTH to BOTHE then how can I specifically ask for the tag with prop B.

I have also tried doing :

SELECT FROM Connected WHERE IN=(SELECT FROM TAG WHERE prop = 'A') AND OUT = (SELECT FROM TAG WHERE prop = 'B')

but I don't get anything from that

Update:

select from Connected where (out in (select from Tag where tagName='testTagA') AND in in (select from Tag where tagName='testTagB')) OR (out in (select from Tag where tagName='testTagB') AND in in (select from Tag where tagName='testTagA'))

this solves the issue but isn't there a more straightforward way? I think this scans all the edges with the given label.

2

2 Answers

0
votes

Try this query

select from Connected where out in (select from Tag WHERE prop = 'B' ) and in in (select from Tag WHERE prop = 'A' )
0
votes

Try this:

1:

SELECT FROM (
    SELECT EXPAND(BOTHE('Connected')) FROM Tag WHERE prop='A'
) WHERE in.prop='B' or out.prop='B'

2:

SELECT FROM Connected 
WHERE (in.prop = 'A' AND out.prop = 'B') OR (in.prop = 'B' AND out.prop = 'A')

2b:

SELECT FROM Connected 
LET $inProp = in.prop, $outProp = outProp = out.prop 
WHERE ($inProp = 'A' AND $outProp = 'B') OR ($inProp = 'B' AND $outProp = 'A')

I'm not sure which is fastest thou, you have to try it out since it depends on your db and other parts of the query. 2b is faster than 2, but only by a super small margin.