Select * from source-(edge)-target doesn't work in GSQL queries

Hi,
I am trying to run a query which finds employees who have been working in a company older than 20 years and then prints details of both employees and organisation.
Below is the sample query:

CREATE QUERY employee_organisation(int company_age) FOR GRAPH dummy{
start = {Employee.*};
old_org_employee_query_1 = SELECT * FROM start:s-(works_in:e)-organisation:t where t.age>company_age; 

#old_org_employee_query_2 =  SELECT s,t FROM start:s-(works_in:e)-organisation:t where t.age>company_age; 

print old_org_employee_query_1[employee.name, employee.salary, organization.name, organisation.revenue]
}

I want to know if there is any way we can make old_org_employee_query_1 or old_org_employee_query_2 work in such fashion.

Thanks,
Mohit

@mt_nagarro there are different ways to approach this. One way is to grab the edges from employee to company and accumulate those into a list. See below for this approach:

CREATE QUERY employee_organisation(int company_age) FOR GRAPH dummy{
ListAccum<EDGE> @@emp2company;
start = {Employee.*};

# Selecting all employees that are in a company that is greater than age of x
old_org_employee_query_1 = SELECT s FROM start:s-(works_in:e)-organisation:t 
                           WHERE t.age > company_age
                           ACCUM @@emp2company += e;

PRINT @@emp2company;
}
Here is another way:

CREATE QUERY employee_organisation(int company_age) FOR GRAPH dummy{
SetAccum<VERTEX> @company;
start = {Employee.*};

# Selecting all employees that are in a company that is greater than age of x
old_org_employees = SELECT s FROM start:s-(works_in:e)-organisation:t 
                           WHERE t.age > company_age
                           ACCUM @company += t;

PRINT old_org_employees;
}
1 Like