Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 problem with subquery

Author  Topic 

simpleweb
Starting Member

1 Post

Posted - 2009-07-17 : 19:46:06
I'm having trouble to this query to work

SELECT <SOME FIELDS>
FROM TABLE1 T1
WHERE <SOME CONDITYIONS>
AND EXISTS(SELECT DISTINCT TOP 10 FIELD1
FROM TABLE2 T2
T2.FIELD1 = T1.FIELD1
AND <SOME OTHER CONDITIONS>)

seems like the distinct is ignored. any idea, how to do this query?

hai
Yak Posting Veteran

84 Posts

Posted - 2009-07-17 : 21:47:48
select (some fields) from
table1 t1
inner join
(select distinct top 10 field1 from table2) t2
on t1.field1=t2.field1
where (some fields)
and (some other fields)
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-17 : 22:40:09
[code]
SELECT <SOME FIELDS>
FROM TABLE1 T1
INNER JOIN
(
SELECT <SOME FIELDS>, ROW_NO = ROW_NUMBER() OVER ( PARTITION BY <SOME COLUMNS> ORDER BY <SOME COLUMNS>)
FROM TABLE2
) T2 ON T1.FIELD1 =T2.FIELD1 AND ROW_NO <= 10
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -