C#中mysql语句实现问题

想把下面两条语句合成一条,实现的是查询接单人(未接单时为空)电话和订单信息的功能,第一条是有接单人,第二条没有,该怎么合并呢?谢谢大家!
1.mycmd.CommandText = @"select recordID,state,deadLine,revent,phone from
records,users where
records.serverID is not null and records.serverID=users.stuID and
records.userID='" + ShareClass.ID + "')";
2.mycmd.CommandText = @"select recordID,state,deadLine,revent from
records where
records.serverID is null and records.userID='" + ShareClass.ID + "'";

4个回答

已经找到合适的写法了:
select recordID,state,deadLine,revent,phone from
records left join users on records.serverID=users.stuID where
records.userID=''
谢谢大家

两条都把phone都取出来不行吗?

zaixiac
_ksy 能实现的话也可以,但是 如果用 3.@"select recordID,state,deadLine,revent,**phone from records,users** where records.serverID is null and records.userID='" + ShareClass.ID + "'"; 就会出现records表中查到的记录与users表中的所有phone组合,却不是phone显示为空
接近 3 年之前 回复

能实现的话也可以,但是 如果用
3.@"select recordID,state,deadLine,revent,**phone from
records,
users** where
records.serverID is null and records.userID='" + ShareClass.ID + "'";
就会出现records表中查到的记录与users表中的所有phone组合,却不是phone显示为空

select recordID,state,deadLine,revent,phone from
records,users where
records.serverID is not null and records.serverID=users.stuID and
records.userID=''
UNION
select recordID,state,deadLine,revent ,phone as null from
records,users where
records.serverID is null and records.userID=''
这样可以不,你试试

zaixiac
_ksy 总是提示在as null之后的语句里有语法问题,没找出原因
接近 3 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问