Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Table 1
--- ----------------- ------- ---------
ID      Chapter       Theory   Problem
--- ----------------- ------- ---------
1         abc            5        3
2         xyz            4        2
3         def            10       15
---------------------------------------

Hello All Of You
Please Help Me!!!!
I has Two Tables
Table2 Contains Thousand Questions

I Want to select Records From Table2
Using Table 1
i.e. I Want Select 5 Theory And 3 Problems Random Question From Chapter abc Which Has 1000 Question
Select 4 Theory And 2 Problems Random Question From Chapter Xyz Which Has 1000 Question
Posted
Updated 27-Dec-11 2:23am
v2
Comments
[no name] 27-Dec-11 7:51am    
This sounds like a homework assignment, and we don't do homework

select 5 theory Question from chapter 'abc'
to achive task note following things
1. To make a join your table1 and table2 should have at least one unique column, in your case it may be 'chapter'
2. use newid() in build function to get random records
SQL
//random 5 theory Question from chapter 'abc'
select Top 5 * from Table2 where Chapter ='abc' order by newid()
 
Share this answer
 
Comments
aviporje 27-Dec-11 8:13am    
Thanks Dear
But How can I Get Value 5 From Table1
There List Of Chapter & I Want to Selected Question From All Chapter
To do this, You have to select records using join from both tables. Following link will help you to write query
SQL Joins[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900