SELECT
    *
FROM
    `matched_activities` AS `ma_main`
WHERE
    `created_at` < "2018-05-22 18:40:23.700872" AND `created_at` > "2018-05-22 16:50:23.700957" AND NOT EXISTS(
    SELECT
        1
    FROM
        `searches`
    WHERE
        (
            searches.id = ma_main.search1_id OR searches.id = ma_main.search2_id
        ) AND `deleted_at` IS NOT NULL
) AND NOT EXISTS(
    SELECT
        1
    FROM
        `searches` AS `searches_outer`
    WHERE
        searches_outer.id = ma_main.search1_id AND EXISTS(
        SELECT
            1
        FROM
            `searches` AS `searches_inner`
        WHERE
            searches_inner.user_id = searches_outer.user_id AND EXISTS(
            SELECT
                1
            FROM
                `matched_activities` AS `ma_same_user`
            WHERE
                (
                    ma_same_user.search1_id = searches_inner.id AND `ma_same_user`.`user1_last_notification_at` > "2018-05-21 18:50:23"
                ) OR(
                    ma_same_user.search2_id = searches_inner.id AND `ma_same_user`.`user2_last_notification_at` > "2018-05-21 18:50:23"
                )
        )
    )
)