SELECT
* ,
REPLACE(TDFG.xdfd,'doc_111','') GB
FROM
(
SELECT
*
FROM
(
SELECT
*
FROM
(
SELECT
*,
CASE sender
WHEN 'doc_111'
THEN CONCAT(receiver,sender)
ELSE CONCAT(sender,receiver)
END 'xdfd'
FROM
user_msg )TTTT
ORDER BY
create_time DESC) t
GROUP BY
xdfd ) TDFG
INNER JOIN
user_doc SSD
ON
SSD.id=REPLACE(TDFG.xdfd,'doc_111','')