日期:2014-05-18  浏览次数:20514 次

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)