orientdb sql query to select edge and vertex fields property.

martin picture martin · Feb 16, 2015 · Viewed 10.5k times · Source

I do have following database structure.

users -> comment -> products

a. users and products are the vertexes that contain some info etc: user_name, product_name and .... b. comment is the edge that contains comment and created/modified date.

what is the sql query may look like in order to show the following result.

Note: i have to show all of the products that may have or no have comment.

  1. product_name, user_name, comment, comment_created_date, comment_modified_date
  2. product_name, user_name, '', '', ''
  3. product_name, user_name, comment, comment_created_date, comment_modified_date

Answer

vitorenesduarte picture vitorenesduarte · Feb 18, 2015
create class User extends V
create property User.name string

create class Product extends V
create property Product.name string

create class Comment extends E
create property Comment.comment string
create property Comment.createDate datetime
create property Comment.modifiedDate datetime


create vertex User set name = 'u1' # 12:0
create vertex Product set name = 'p1' # 13:0
create vertex Product set name = 'p2' # 13:1

create edge Comment from #12:0 to #13:0 set comment = 'nice product', createDate = sysdate()

If the above is your situation, I believe the query you're looking for is something like:

select *, expand(inE('Comment')) from Product

UPDATE:

It's not very pretty, but as a workaround you could use:

select *, inE('Comment').include('comment', 'createDate', 'modifiedDate') from Product