Skip to content
Advertisement

MySql : how to join this two tables with multiple pivot

I want to get the last activity of my client but i dont know how to that that with two tables that have more than one pivot. Please look at to the example below :

I want this result (last activity is the lastest date of (check_mo and check_pa). and relationship between tables is (account.id => product.check_mo_account_id and product.check_pa_account_id))

Advertisement

Answer

If I understand correctly, you have two check IDs and two check dates in one row, but want to treat them equally, just as if you had just one table with one check ID and one check date per row. Use UNION ALL to get this table. Then find the maximum date per ID and join this to the account table.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement