读书人

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

发布时间: 2012-09-24 13:49:41 作者: rapoo

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

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+"'" 

读书人网 >SQL Server

热点推荐