Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQL-选择多个值_Sql_Sql Server 2008 - Fatal编程技术网

SQL-选择多个值

SQL-选择多个值,sql,sql-server-2008,Sql,Sql Server 2008,我有两张桌子: 第一个表(Departs)包含以下列: 1 - departid 2 - departname 1 - messageID 3 - SentFromDepartID 4 - SentToDepartID 5 - ReplyMessage 6 - mdate 第二个表(消息)包含以下列: 1 - departid 2 - departname 1 - messageID 3 - SentFromDepartID 4 - SentToDepartID 5 - ReplyMess

我有两张桌子: 第一个表(Departs)包含以下列:

1 - departid
2 - departname
1 - messageID
3 - SentFromDepartID
4 - SentToDepartID
5 - ReplyMessage
6 - mdate
第二个表(消息)包含以下列:

1 - departid
2 - departname
1 - messageID
3 - SentFromDepartID
4 - SentToDepartID
5 - ReplyMessage
6 - mdate
我想查询有关邮件的信息,并获取出发点的名称,而不是出发点的号码。你能帮我吗

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