我有两个表,tbl_msg ...SQL查询涉及到两个表
tbl_user
我想选择所有从tbl_msg其中封邮件toid = 42以及已发送msg的人员的姓名(而不是fromid)。结果应该是这个样子..
|fromid(name, not the id)| Msg| toid(name!,which belongs to id 42)|some other column from msgid|
查询:
select tbl_msg.[MsgId]
,tbl_User.FirstName as sentby
,tbl_msg.[ToId]
,tbl_msg.[Msg]
from
tbl_msg
inner join
tbl_User on tbl_msg.FromId = tbl_User.ID
where
tbl_msg.ToId = 42
但这只会给我的名字相应fromid,而不是两个风湿名称和fromid
这怎么可能做了什么?
消息4104,级别16,状态1,行8 多部分标识符 “tbl_msg.ToId” 不能被约束。 – Arbaaz
Fxied。再试一次,它会工作:) – gzaxx
工程就像一个魅力! ;) – Arbaaz