You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@age.apache.org by "WendelLana (via GitHub)" <gi...@apache.org> on 2023/05/29 14:20:27 UTC

[GitHub] [age] WendelLana commented on issue #951: How to use WHERE caluse after a (WITH .. AS ...)

WendelLana commented on issue #951:
URL: https://github.com/apache/age/issues/951#issuecomment-1567203145

   In your particular case, you don't need to use a WHERE clause, it's simply replaced with a MATCH clause, like this:
   ```
   SELECT * from cypher('munmud', $$
   MATCH (u:User {id: 'user1'})-[:WATCHED]->(m:Movie)
   WITH DISTINCT m as watchedMovies
   	MATCH (g:Genre)<-[]-(watchedMovies)
   	WITH DISTINCT g as genre
   		MATCH (genre)<-[:BELONGS_TO]-(am)
   		WITH DISTINCT am as allMovie
   			MATCH (u:User {id: 'user1'})-[:WATCHED]->(allMovie)
   			RETURN allMovie
   $$) as (V agtype);
   ```
   
   However, I didn't get why you need all this MATCH clauses if your query would return the same result with a simple query like this:
   ```
   SELECT * from cypher('munmud', $$
   MATCH (u:User {id: 'user1'})-[:WATCHED]->(m:Movie)
   RETURN m
   $$) as (V agtype);
   ```
   If you want to get all movies genres watched by a particular person than return all movies that another person watched from those same genres using a WHERE clause, you could do this:
   ```
   SELECT * from cypher('munmud', $$
   MATCH (u:User {id: 'user1'})-[:WATCHED]->(m:Movie)
   WITH DISTINCT m as watchedMovies
   	MATCH (g:Genre)<-[]-(watchedMovies)
   	WITH DISTINCT g as genre
   		MATCH (genre)<-[:BELONGS_TO]-(am)
   		WITH DISTINCT am as allMovies
   			MATCH (u:User)-[:WATCHED]->(allMovies)
   			WITH u as user, allMovies as movie
   				WHERE user.id = 'user2'
   				RETURN movie
   $$) as (V agtype);
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@age.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org