estevammr
estevammr

Reputation: 37

OrientDB query compare

I have the following doubt to query in OrientDB.

I have three vertex users, events and sports.

First users choose sports and at that point the has_sport edge is created, which has the 'out' on the user and 'in' on the sports.

And having some events registered by other users as follows, users-> events-> sports, users create edge 'out' and 'in' events and events edge 'out' and 'in' sports.

Now the question of how to do the query, I want to make a query that returns the events to the user according to the sports that he chose. In other words, to see if the user sports is equal to the events sport.

Vertex: users, events, sports Edges: has_sport, has_event

Image graph

Sorry for my bad english hehe

Thank you

EDIT

    SELECT expand(event) FROM (
      MATCH 
        {class:users, as:user, where:(userId = ?)} -has_sport-> {as:sport},
        {class:events, as:event} -has_sport-> {as:sport},
        {as:user} -has_sport-> {as:sport}
    RETURN event
    )

Upvotes: 0

Views: 66

Answers (2)

Luigi Dell'Aquila
Luigi Dell'Aquila

Reputation: 2814

You can consider using a MATCH statement:

MATCH 
  {class:User, as:user, where:(userId = ?)} -has_event-> {as:event} -has_sport-> {as:sport},
  {as:user} -has_sport-> {as:sport}
RETURN event

This will return the event RIDs. If you want expanded records, you can wrap it in a SELECT expand() eg.

SELECT expand(event) FROM (
  MATCH...
)

Upvotes: 1

Vineeth
Vineeth

Reputation: 135

Hope this works..

select out.name as sports, in('has_event').name as eventname from (select expand(out('has_sport')) from User where userid = 151)

Please verify the "out" / "in" logic. if required change it.

Upvotes: 0

Related Questions