Is there a function that, for each value in dataSet_1, do a search in a dataSet_2 based in more than one condition? It's like in SQL, for each value, do a new search.
SELECT
value1Table1,
value2Table1,
(
SELECT MIN(value) FROM table_2 AS table_2
WHERE table_2.value1 = table_2.value1 AND table_1.Date > table_2.Date
) AS value1table2,
value3Table1
FROM table_1
Changed from MAX to MIN and < for > the have a query for the example below:
I'll try to explain a little more. Normally I use something like this in cases where I have a date (factDate) and for each user (that have your own different date) I need to search the first event that happened after the factDate.
Example:
Table_1
|User|TargetEventDate|NextEventDate| <- Value that I want
|A |2018-04-17 |2018-04-18 | <- Value to Find
|B |2018-04-14 |2018-04-15 | <- Value to Find
Table_2
|User|DateEvent |
|A |2018-04-19|
|A |2018-04-18| <- Value that I want for user A
|A |2018-04-17| <- Value used in Table_1 for user A
|A |2018-04-13|
|A |2018-03-10|
|B |2018-04-17|
|B |2018-04-15| <- Value that I want for user B
|B |2018-04-14| <- Value user in Table_1 for user B