易截截图软件、单文件、免安装、纯绿色、仅160KB

求一条SQL语句

有两个表一个是人员表user,一个是信息表info


user表 info表
id 姓名 性别 id 姓名 信息
1 张三 男 1 张三 信息一
2 李四 女 2 张三 信息二
3 王五 男 3 李四 信息三
  4 张三 信息四
  5 李四 信息五

两个表的关联字段是姓名
希望的结果是
张三 男 信息一
李四 女 信息三
王五 男 空
SQL code:
SELECT U.*,I.信息 from USER U LEFT JOIN INFO I ON U.ID=I.ID


user表 
id 姓名 性别 
1 张三 男 
2 李四 女 
3 王五 男 
 
 

info表
id 姓名 信息
1 张三 信息一
2 张三 信息二
3 李四 信息三
4 张三 信息四
5 李四 信息五

select m.姓名 ,m.性别 ,isnull(n.信息,'空') 信息
from [user] m left join info n on m.姓名 = n.姓名

引用
user表
id 姓名 性别
1 张三 男
2 李四 女
3 王五 男



info表
id 姓名 信息
1 张三 信息一
2 张三 信息二
3 李四 信息三
4 张三 信息四
5 李四 信息五

如果是最开始的需求:
select m.姓名 ,m.性别 ,isnull(n.信息,'空') 信息
from [user] m left join info n on m.姓名 = n.姓名

如果是后面的:
select m.


相关问答:

jsp链接sql2000的疑问?



type Exception report


message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jas ......

ASP链接SQL的简单登陆界面 - .NET技术 / ASP.NET

protected void btnLogin_Click(object sender, EventArgs e)
  {
  SqlConnection conn = new SqlConnection("Server = (local);user id = sa;pwd = 1;database = Login");
&nb ......

求一SQL - MS-SQL Server / 基础类

tab1 字段:billdate,goodsid,incount,inmoney,outcount,outmoney,endprice,endcount,endamt
tab2 字段:goodsid,goodskind(商品类型)
tab3 字段:goodskind(商品类型),kindname
结果:
得到商品类型在一段时间 ......

请教SQLSERVER的两个问题 - MS-SQL Server / 疑难问题

1。怎样使xp_cmdshell能完整输出超过255个字符的字符串。
2。select 时,检索速度是与from后的 TABLE顺序有关,还是与where条件的顺序有关(TABLE数据多少 )
在系统属性设定里有个选项,可以修改单字段输出字数限制. ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号