| Author |
Topic |
|
BankOfficerHere
Posting Yak Master
124 Posts |
Posted - 2011-10-19 : 15:35:37
|
| I have this statement:select top 1 (select top 1 * from dbo.table2)from dbo.tableI would like to get the text value of select top 1 * from dbo.table2select top 1 * from dbo.table2 = 1 as Q1_A |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-20 : 00:24:30
|
| do you mean you want top 1 from table2 matching some conditions based on table1 column?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
BankOfficerHere
Posting Yak Master
124 Posts |
Posted - 2011-10-20 : 08:28:49
|
| That's correct visakh16, is that possible? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
BankOfficerHere
Posting Yak Master
124 Posts |
Posted - 2011-10-20 : 09:17:09
|
| what's it all about? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-20 : 09:23:57
|
| did you even bother to read it?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
BankOfficerHere
Posting Yak Master
124 Posts |
Posted - 2011-10-20 : 09:26:01
|
| sorry..i really didn't get it |
 |
|
|
BankOfficerHere
Posting Yak Master
124 Posts |
Posted - 2011-10-20 : 09:27:22
|
| can you help me do it from my example? i would really appreciate it. |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-10-20 : 09:56:34
|
[code]select <column list>from table1 t1 cross apply ( select top 1 <column list> from table2 t2 where t2.<column> = t1.<column> order by <column> ) t2[/code]Please refer to Books Online for syntax and explainationhttp://technet.microsoft.com/en-us/library/ms175156.aspx KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
BankOfficerHere
Posting Yak Master
124 Posts |
Posted - 2011-10-20 : 10:07:09
|
| almost there..but column name should be Q1_A and result should be 1 |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-10-20 : 10:28:50
|
That's Good. I am sure you can modify the query and put in the actual table name and column name yourself KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-21 : 00:56:07
|
quote: Originally posted by BankOfficerHere sorry..i really didn't get it
If thats case you should have at least posted your tried query. Unless you try it you will not understand concept and usage------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|