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 |
|
Easwar
Yak Posting Veteran
59 Posts |
Posted - 2007-03-15 : 06:13:02
|
| I've two table.......One table Name Form1Ex----------Name|F1No----|-----23wa|1xyzx|2abcd|3..................---------F1No====>primary KeySecond table Name Form2Ex--------F2No----312221..................--------F2No===>Foreign Keyi want top 3 Name(field) in first table(Form1).Result------xyzx23waabcd |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-15 : 06:17:55
|
| select top 3 namefrom form1order by f1no descPeter LarssonHelsingborg, Sweden |
 |
|
|
Easwar
Yak Posting Veteran
59 Posts |
Posted - 2007-03-15 : 06:23:36
|
| that query i can't get resultthat is wrong query...that query no based second table(form2) |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-15 : 06:25:31
|
| Wrong query?It gives the result you want (at least as you have posted it).Maybe you should be more clear about your objective here, and why there is a need to JOIN the two tables.Peter LarssonHelsingborg, Sweden |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-15 : 06:28:33
|
| Or you mean TOP 3 according to number of records of each?SELECT TOP 3 f1.NameFROM Form1 AS f1INNER JOIN Form2 AS f2 ON f2.F2No = f1.F1NoGROUP BY f1.Name, f1.F1NoORDER BY COUNT(*) DESCPeter LarssonHelsingborg, Sweden |
 |
|
|
Easwar
Yak Posting Veteran
59 Posts |
Posted - 2007-03-15 : 06:34:24
|
| i need top 3 name. ( top 3 name means in second table maximum selected value.. My ex table mentioned. in second table F2No field 2 is one or time selected. so i need that no(2 is top) in my first table mention name(xyzx), so my result table i mentioned first position(2))...now are u clear... |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-15 : 06:37:00
|
| I already posted a working query 8 minutes ago. Have you tried that?Peter LarssonHelsingborg, Sweden |
 |
|
|
Easwar
Yak Posting Veteran
59 Posts |
Posted - 2007-03-15 : 06:42:59
|
| SELECT TOP 3 f1.NameFROM Form1 AS f1INNER JOIN Form2 AS f2 ON f2.F2No = f1.F1NoGROUP BY f1.Name, f1.F1NoORDER BY COUNT(*) DESCThis query now workedVery very thanks......... |
 |
|
|
|
|
|