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)
 retrieve particular no of records from table

Author  Topic 

ssmani84
Starting Member

20 Posts

Posted - 2010-07-05 : 01:22:54
hi friends,
I want to retrieve particular no of records from table with Condition..

my table structure is
QID Question Status
1 ssssss True
2 ssssss True
3 ssssss False
4 ssssss False
5 ssssss False

here i want to 3 questions condition is Status Filed TRUE Questions are must be getting..how can i get 3 questions from this table Pls Help me

my query is below
select top (3) QuestionID,Question from Question
where Status='True'

but this query return only 2 values

ssmaniyadav

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-07-05 : 01:45:07
you have only 2 rows in the table with Status = 'True'

What do you want the 3rd record be like ?


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

Go to Top of Page

ssmani84
Starting Member

20 Posts

Posted - 2010-07-05 : 01:56:56
I want to 3 rows from this table ..i dont know the exact query..i need to return 2 rows in the table with Status = 'True' and 1 row in the table with Status = 'False'

ssmaniyadav
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-07-05 : 02:06:00
[code]
select top (3) QuestionID,Question from Question
where Status='True'
order by Status desc
[/code]


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

Go to Top of Page

ssmani84
Starting Member

20 Posts

Posted - 2010-07-05 : 02:34:03
Thanks Khtan...its working fine

ssmaniyadav
Go to Top of Page
   

- Advertisement -