How To Fetch Data From One Class To Another In Orientdb
I have created two classes customer and city. customer class contain two properties name and location and city class contain id and location . I want to perform join operations on these two classes. I create a graph relation in orientdb studio and fire a query below
select from customer where city.location='pune'
but this query not returning any value,it executed but not returning any field, So, this is correct syntax or i am doing wrong in somewhere .. please give me solutions.
Answer
I have this simple dataset to give you some examples:
create class Customer extends V
create class City extends V
create class livesAt extends E
create property Customer.name String
create property City.id integer
create property City.location String
create vertex Customer set name="Tom"
create vertex Customer set name="John"
create vertex City set id=1, location="London"
create vertex City set id=2, location="Pune"
create edge livesAt from (select from Customer where name="Tom") to (select from City where id=1)
create edge livesAt from (select from Customer where name="John") to (select from City where id=2)
Now you can use different queries to retrieve the results you're looking for.
Query 1a: Starting from Customer (like your query above)
select from Customer where out('livesAt').location in 'Pune'
Output:
----+-----+--------+----+-----------
# |@RID |@CLASS |name|out_livesAt
----+-----+--------+----+-----------
0 |#12:1|Customer|John|[size=1]
----+-----+--------+----+-----------
Query 1b: Starting again from Customer
select from Customer where out('livesAt').location contains 'Pune'
Output:
----+-----+--------+----+-----------
# |@RID |@CLASS |name|out_livesAt
----+-----+--------+----+-----------
0 |#12:1|Customer|John|[size=1]
----+-----+--------+----+-----------
Query 1c:
select from Customer where out('livesAt')[location = 'Pune'].size() > 0
Output:
----+-----+--------+----+-----------
# |@RID |@CLASS |name|out_livesAt
----+-----+--------+----+-----------
0 |#12:1|Customer|John|[size=1]
----+-----+--------+----+-----------
Query 2: Starting from City (more direct)
select expand(in('livesAt')) from City where location = 'Pune'
Output:
----+-----+--------+----+-----------
# |@RID |@CLASS |name|out_livesAt
----+-----+--------+----+-----------
0 |#12:1|Customer|John|[size=1]
----+-----+--------+----+-----------
Hope it helps
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → I can't do a foreign key, constraint error
- → Setting a default value on settings form return null in Octobercms
- → Eloquent Multitable query
- → "Laravel 5.1" add user and project with userId
- → Image does not go in database with file name only tmp name saved?
- → Database backup with custom code in laravel 5 and get the data upto 10 rows from per table in database
- → Trait 'IlluminateFoundationBusDispatchesJobs' not found
- → Setting the maxlength of text in an element that is displayed
- → laravel check between 2 integer from database
- → how to retrieve image from database in laravel 5.1?
- → relationship for database Column type object
- → Carousel in Laravel 4 does not show as expected