首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

帮写一条两个表连接的语句,该如何处理

2012-09-24 
帮写一条两个表连接的语句SQL code表usermessage(id,username,password,touxiang)和表table20(id,username

帮写一条两个表连接的语句

SQL code
表usermessage(id,username,password,touxiang)和表table20(id,username,title,time,content),其中usermessage和table20中有一共同字段username,现在我想得到这样的结果:显示 表A的username,touxiang,表B的title、time、content ,where条件是根据table20的id来查询,传入的参数是string id4大概代码如下:   string SqlStr4="select username,touxiang,title,time,content from usermessage and table20 where  table20.id='"+id4+"'";


[解决办法]
SQL code
select a.username,a.touxiang,b.title,b.time,b.content from usermessage aleft join table20 b on a.username=b.usernamewhere b.id=
[解决办法]
SQL code
select a.username,a.touxiang,b.title,b.time,b.content from usermessage aleft join table20 b on a.username=b.usernamewhere b.id=
[解决办法]
C# code
string SqlStr4="select a.username,a.touxiang,b.title,b.time,b.content from usermessage a,table20 b where a.username=b.username and b.id='"+id4+"'";
[解决办法]
SQL code
SELECT  a.username ,        a.touxiang ,        b.title ,        b.time ,        b.contentFROM    usermessage a        INNER JOIN table20 b ON A.username = b.usernameWHERE   b.id = @id
[解决办法]
SQL code
select username,touxiang,title,time,content from usermessage a left join table20 b on a.id=b.id and a.username=b.usernamewhere  b.id='"+id4+"'" 

热点排行