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

求简单sql - MS-SQL Server / 基础类

table1:
id name sub

1 q w

2 r t

3 y n


table2:
id title_id text

1 3 u

2 2 i

3 1 p

4 2 b

5 1 m


求sql语句 查询出 title_id 相同的项 并且查出在table1中 id = title_id 列的name
结果:
  2 2 i r

  2 2 b r

2 2 b r 第一个2是不是该为4啊?

你给的数据和结果貌似不对.



SQL code:
select a.id,b.title_id,b.text,a.sub from table1 a join table2 b on a.id=b.title_id


title_id table1中id text name

2 2 b r

2 2 i r


结果不对吧

SQL code:
--结果好像有出入
if not object_id('table1') is null
drop table table1
Go
Create table table1([id] int,[name] nvarchar(1),[sub] nvarchar(1))
Insert table1
select 1,N'q',N'w' union all
select 2,N'r',N't' union all
select 3,N'y',N'n'
Go
if not object_id('table2') is null
drop table table2
Go
Create table table2([id] int,[title_id] int,[t


相关问答:

sql小小的疑问 - .NET技术 / C#

可能因为工作的原因 接触数据库这块比较少,之前都是做程序这块,数据库这块都有专门的人来做 分工都很明细 所以对数据库这一块完全不了解。前段时间 去面试了几家公司 几乎都是在数据库这块挂掉的 连个简单的SQ ......

MS SQL作业问题 - MS-SQL Server / 应用实例

如何在SQL2005中设定定时作业,比如说定时清理某些表的数据,
或者是定时的将某些表的数据导出excel!
在线等待,急急急,最好是详细步骤!
之前我做的作业有点问题!
帮UP

参考:http://hi.baidu.com/toiota ......

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

1。怎样使xp_cmdshell能完整输出超过255个字符的字符串。
2。select 时,检索速度是与from后的 TABLE顺序有关,还是与where条件的顺序有关(TABLE数据多少 )
在系统属性设定里有个选项,可以修改单字段输出字数限制. ......

SQL语句问题 - MS-SQL Server / 疑难问题

请教高手:
 以下是数据库中的三条记录,英文为字段名称  
  id planname TaskBeginTime Status
329 2010年03 ......

关于Vb中sql语句的写法(100分) - Java / Web 开发

求个vb中的sql语句的写法,次sql语句的用法是分页程序
我写的如下:其中A是用来接收每页显示的记录的条数,B是用来接收显示的当前的页面.
sqltext="select top A * from log where id not in(select top ( ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号