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 |
misterraj
Yak Posting Veteran
94 Posts |
Posted - 2009-03-17 : 02:21:48
|
i have a table with following columns,col1 col2-----------a 1 a1 1a2 2a3 2a4 2 i need a query which will read the first record take the value of col2 and then return all the records of type col2='1'.then it will give me records of type coll2='2'how do i write the t-SQL ? |
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-03-17 : 02:24:32
|
can u explain clearly and post ur required output? |
|
|
misterraj
Yak Posting Veteran
94 Posts |
Posted - 2009-03-17 : 02:28:01
|
col1 -------------col2a------------------1a1-----------------1a2-----------------2a3-----------------2a4-----------------2a5-----------------1i need a query which will give me all the records of col2='1' (the value of the first record)how will i write the t-sql. note that col2 value could be anything....... |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-03-17 : 02:29:29
|
select * from table where col2 = 1 |
|
|
misterraj
Yak Posting Veteran
94 Posts |
Posted - 2009-03-17 : 02:30:33
|
thats too smart nageswar! i said i will not know the value of the first record! |
|
|
misterraj
Yak Posting Veteran
94 Posts |
Posted - 2009-03-17 : 02:35:28
|
no answers? or the question was not understood? |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-03-17 : 02:36:24
|
ok,try this onceselect * from @temp where col2 = ( select top 1 col2 from @temp) |
|
|
misterraj
Yak Posting Veteran
94 Posts |
Posted - 2009-03-17 : 02:47:33
|
well i found myself thanks.Select top 4 * from PTAX where product_id in (select top 1 product_id from PTAX)thanks nageswar too, that was the same as i did.. |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-03-17 : 02:58:57
|
quote: Originally posted by misterraj well i found myself thanks.Select top 4 * from PTAX where product_id in (select top 1 product_id from PTAX)thanks nageswar too, that was the same as i did..
Ok Welcome |
|
|
|
|
|