我有两张桌子: 第一个表(Departs)包含以下列:
1 - departid
2 - departname
第二个表(消息)包含以下列:
1 - messageID
3 - SentFromDepartID
4 - SentToDepartID
5 - ReplyMessage
6 - mdate
我想查询消息并获取离开的名称而不是离开号码。你能救我吗?
答案 0 :(得分:2)
select m.*,
dfrom.departname as fromname,
dfrom.departname as toname
from messages m
join departs dfrom on dfrom.departid = m.sentfromdepartid
join departs dto on dto.departid = m.senttodepartid