Reputation: 2460
I'm experimenting with OrientDb with the sample vehicle history database and have executed these two SQL queries, which I (would have thought) would be identical. I am trying to find all of the females who sold a vehicle to a male.
SELECT expand(out('Bought').in('Sold')[gender="Female"]) FROM Person
WHERE gender = "Male" LIMIT = -1
This one returns 124 records.
While
SELECT FROM ( TRAVERSE in('Sold') FROM (
SELECT FROM ( TRAVERSE out('Bought') FROM (
SELECT FROM Person WHERE gender = "Male")
) WHERE @class = "Transaction" ))
WHERE @class = "Person" and gender = "Female" LIMIT = -1
Returns 117 records.
I was hoping someone could explain to me what the difference is?
Upvotes: 1
Views: 406
Reputation: 9060
@codemix is right, to have the same result use set() that excludes duplicated:
SELECT FROM (
TRAVERSE in('Sold') FROM (
SELECT FROM (
TRAVERSE set( out('Bought') ) FROM (
SELECT FROM Person WHERE gender = "Male"
)
) WHERE @class = "Transaction"
)
)
WHERE @class = "Person" and gender = "Female" LIMIT = -1
Upvotes: 1
Reputation: 672
We resolved this on gitter, but for anyone else wondering - this happens because the second query will remove duplicates (because of the traverse) but the first one won't.
Upvotes: 2