cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MrNigel
Advocate V
Advocate V

How to do a 1:1 SQL SELECT join across two SharePoint lists

I have searched everywhere for the answer to this requirement and cannot find a match for what must be a common requirement.  This would normally be done using a simple SQL SELECT statement, but this is not supported in Flow ☹

 

I want to do a 1:1 join across two SharePoint lists where the join is the unique column ‘EmployeeEmail’.

 

  • Table1 contains the Employee details – one row per employee
  • Table2 contains a minimum of 1 up to a maximum of 5 employee objectives – one row per employee

I have tried using Get List to load Table1 into an array but have got stuck trying to append the Objectives in Table2 to the end of each row in the array.  Do I need one of the Data Operations actions?

 

The output of this query is going to be fed into the FormsPro Send a Survey action.

 

TIA folks!

6 REPLIES 6
Pstork1
Dual Super User
Dual Super User

Run a Get Items for each list and then try using the Union() function.  There is no easy way to do the equivalent of a Join with SharePoint lists.  But I've used Union() to do this in the past if there is a Lookup column in the second list that points back to the first.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Hi Paul,

 

The challenge is I want to append the output from List2 onto the end of List1 (using 'where list1.email=list2.email' as my join) which is why I was trying arrays.  Union just adds the two lists together.  This is so easy to do using SQL SELECT but there is no SELECT command in the expression builder.  Why not I wonder?

 

Tks

 

Nigel

 

If there is a Lookup column in List 2 based on list1.email then union should do what you want it to.  

 

The reason there is no Select where in Power Automate for SharePoint is that SharePoint isn't a relational database.  Its flat tables.  Select Where works in SQL because SQL is designed to be relational.  SharePoint isn't (other than when you simulate relationships using Lookup columns).



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Peter,

 

There is indeed a Lookup column.  List1 contains all employees and List2 contains their objectives.  When creating a new objective you pick the user email from List1 via a lookup.

 

What is the syntax for the union expression?  There doesn’t seem to be anything other than the two lists.  Does it magically work out they are joined via the email Lookup column?

 

Thanks,

 

Nigel

In my tests, if you do Union(List1, List2) it will automatically match the records from list 2 based on the lookup column.

 

Your only other choice would be to build an array of objects manually using two Apply to each loops.  The outer loop will go through each entry in List 1 and the inner loop will go through list 2 looking for a matching email.  When it finds it the inner loop will write an entry to the array containing the value from List 1 and list 2 that match.  Its really manual, but it will work.  Just not sure how performant it will be.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

This is the Union statement I tested: 

union(body('Get_items_-_Employee_List'),body('Get_items_-_Objectives_List'))
 
It just adds ObjectivesList below EmployeeList rsather than 'unioning' them.
 
I will try the Array suggestion - many thanks for this input it is much appreciated.
 
Nigel

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Users online (3,286)