I have a sessions table with three columns
And I have a table of user's actions with datestamps
To the user's action table, I would like to add a column that states in which session # that action took place, based on the dates
I was thinking of making a for loop where I take each row of user_id, and then for that row and inner loop to check if the date of that row is inside row 1 of Sessions (session 1), if not, next iteration will be to check with row 2 of Sessions table, if not, the third row, and so on untill it matches and we can move back to the outer loop to take the next row of User's actions and repeat the process of iterating over sessions table.
But is there a faster computational way to do it? My tables are more than 10 million rows