T-SQL Subquery Question

Posted by Nick on Stack Overflow See other posts from Stack Overflow or by Nick
Published on 2010-05-19T10:20:05Z Indexed on 2010/05/19 10:30 UTC
Read the original article Hit count: 172

Filed under:
|

Hi,

i have two queries. For each tuple of query1 i want to run query2. i dont want to use cursors. i tried several approaches using subqueries.

query1:

select 
    distinct 
    category, 
    Count(category) as CategoryCount
from 
    mytable 
group by 
    category

query2:

select
   top 3 
   Text,
   Title,
   Category
from
    mytable
where
    Category = '1'

Category = '1' is a sample. the value should come from query1

© Stack Overflow or respective owner

Related posts about tsql

Related posts about sql