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.
| Author |
Topic |
|
simpleweb
Starting Member
1 Post |
Posted - 2009-07-17 : 19:46:06
|
| I'm having trouble to this query to workSELECT <SOME FIELDS>FROM TABLE1 T1WHERE <SOME CONDITYIONS>AND EXISTS(SELECT DISTINCT TOP 10 FIELD1 FROM TABLE2 T2 T2.FIELD1 = T1.FIELD1AND <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) fromtable1 t1inner join (select distinct top 10 field1 from table2) t2on t1.field1=t2.field1where (some fields)and (some other fields) |
 |
|
|
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] |
 |
|
|
|
|
|