如何使用SQL查询哪些消息发送给了ID为100的用户?
Moodle 中有 2 个消息表,分别是消息被读取之前和之后
||
是Postgresql中的连接运算符
SELECT 'message' || id AS uniqueid,
useridfrom,
useridto,
subject,
fullmessage,
contexturl,
contexturlname,
timecreated,
0 AS timeread,
timeuserfromdeleted,
timeusertodeleted
FROM mdl_message
WHERE useridfrom = xx
UNION
SELECT 'messageread' || id AS uniqueid,
useridfrom,
useridto,
subject,
fullmessage,
contexturl,
contexturlname,
timecreated,
timeread,
timeuserfromdeleted,
timeusertodeleted
FROM mdl_message_read
WHERE useridfrom = xx