sql 查询语句

[复制链接]
查看11 | 回复4 | 2009-3-31 19:25:52 | 显示全部楼层 |阅读模式
请看上图,我简单的文字描叙下:在Drawing表中,有title和DWname字段,在Archive表中,有title字段我想:查询返回在[Drawing]表中DWname字段中为“张三”的所有列,但title字段不能重复,且返回的这些title中是在[Archive]表的title字段没有显示的。谢谢la

回复

使用道具 举报

千问 | 2009-3-31 19:25:52 | 显示全部楼层
select DWname,title from Drawing whereDWname='张三' and title not in (select title from Archive) group by DWname,titleselect a.DWname,a.title from Drawing a,Archive b where a.titleb.titleand a.DWname='张三'最后一种比前一种和楼上那种效率要高一点,不过这几种结果都是对的...
回复

使用道具 举报

千问 | 2009-3-31 19:25:52 | 显示全部楼层
SELECT DISTINCT Title, DWNameFROM DrawingWHERE (DWname = '张三')AND NOT EXISTS (SELECT *FROM ArchiveWHERE (Title = Drawing.Title))其实楼主你的需求有一个问题。就是“title字段不能重复...
回复

使用道具 举报

千问 | 2009-3-31 19:25:52 | 显示全部楼层
select distinct * from Drawing where not exists ( select * from Archive where Drawing.title=Archive.title ) and DWname = '张三' 我 试过来 ,输出的结果就是你要的 结果有什么不懂的地方就Q我我们一起讨论一下 ,呵呵 ...
回复

使用道具 举报

千问 | 2009-3-31 19:25:52 | 显示全部楼层
select distinct title,DWname from Drawingwhere DWname='张三' and title not in (select title from Archive)...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行