首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

SQL数据库查询有关问题.

2012-03-01 
SQL数据库查询问题..急急急...在线等!!!!!!!!selecta.ID,a.fileContext,b.createDate,b.type,b.Production

SQL数据库查询问题..急急急...在线等!!!!!!!!
select a.ID,a.fileContext,b.createDate,b.type,b.Production_Name,b.Production_Collocate,b.Production_purpose,b.Production_Type,b.Choose_piece,b.Production_id,c.ID,c.myfile,c.myfile1,c.myfile2,c.fileContext,c.fileContext1,c.fileContext2 from [File] as a,Production as b,MyFile as c where b.Production_id=a.ID and b.Production_id=c.ID and b.Production_id=1

Production是主表.File和MyFile是外键表..我要去掉重复记录..因为我MyFile里面的fileContex,fileContex1,fileContex2是image类型的字断.所以不能用distinct关键字..自己拼了半天拼不出来..谁写出来了马上结贴.谢谢...

[解决办法]
select d.* ,e.fileContext AS Expr2, 
e.fileContext1, e.fileContext2
from (
SELECT distinct a.ID, a.fileContext, b.createDate, b.type, b.Production_Name, 
b.Production_Collocate, b.Production_purpose, b.Production_Type, b.Choose_piece, 
b.Production_id, c.ID AS Expr1, c.myfile, c.myfile1, c.myfile2
FROM [File] a INNER JOIN
Production b ON a.ID = b.Production_id INNER JOIN
MyFile c ON b.Production_id = c.ID
WHERE (b.Production_id = 1)) d join MyFile e on (d.id = e.id)

热点排行