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 2000 Forums
 Transact-SQL (2000)
 subquery in from

Author  Topic 

mdhingra01
Posting Yak Master

179 Posts

Posted - 2006-01-20 : 13:49:17
Table A has 50 records and I am selecting and grouping by on only 4 of the 10 columns, the number of records I get back are 20. I want to use this list of 20 records to match up in the entire table A and grab all corresponding records.

This is what I am doing:
Select b.yrmth,
b.regimental,
b.surname,
b.initials,
b.year,
b.division,
b.unit_coll,
b.pos_number,
b.erank,
b.detachment,
b.empl_class,
b.emp_status
from (Select unit_coll, pos_number, erank, yrmth
from ttt as c group by unit_coll, pos_number, erank, yrmth )as a join ttt as b on a.unit_coll=b.unit_coll and a.pos_number=b.pos_number and a.erank=b.erank and a.yrmth=b.yrmth

What is the syntax or the best method for grouping on a subset of data from one table and applying it to the table.

Thanks

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-01-20 : 14:22:23
Ur first selection list can be considered as a different table as follows

Select * from ( Select a,b,c,d from ttt where ....) as Qry where ....

or u can join the selected query with the main table

Note : u should use aliases
Go to Top of Page
   

- Advertisement -