openvk/Web/Models/sql/get-correspondencies.tsql

35 lines
493 B
Text
Raw Permalink Normal View History

2020-06-07 19:04:43 +03:00
SELECT DISTINCT id, class FROM
(
(
SELECT
recipient_id AS id,
recipient_type AS class,
created AS time
FROM messages
WHERE
sender_id = ?
AND
sender_type = ?
AND
deleted = 0
2020-06-07 19:04:43 +03:00
) UNION (
SELECT
sender_id AS id,
sender_type AS class,
created AS time
FROM messages
WHERE
recipient_id = ?
AND
recipient_type = ?
AND
deleted = 0
2020-06-07 19:04:43 +03:00
)
ORDER BY
time
DESC
) dt
LIMIT
?
OFFSET
?