SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL Query
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

nrajeshkumars
Starting Member

India
5 Posts

Posted - 03/05/2014 :  23:58:19  Show Profile  Reply with Quote
ItemID ItemName Price
1 Item1 120.00
2 Item2 234.00
3 Item3 250.00
4 Item4 300.00
5 Item5 300.00
6 Item6 290.00
7 Item7 170.00
8 Item8 90.00
9 Item9 170.00

the above is the existing table
and i need a query to retrieve max price with out using max function and sub query

N.Rajesh kumar

khtan
In (Som, Ni, Yak)

Singapore
17586 Posts

Posted - 03/06/2014 :  00:00:52  Show Profile  Reply with Quote
homework ?


KH
Time is always against us

Go to Top of Page

nrajeshkumars
Starting Member

India
5 Posts

Posted - 03/06/2014 :  00:04:56  Show Profile  Reply with Quote
YES..

quote:
Originally posted by khtan

homework ?


KH
Time is always against us





N.Rajesh kumar
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
17586 Posts

Posted - 03/06/2014 :  00:05:56  Show Profile  Reply with Quote
so can you use the TOP keyword ?


KH
Time is always against us

Go to Top of Page

nrajeshkumars
Starting Member

India
5 Posts

Posted - 03/06/2014 :  00:09:59  Show Profile  Reply with Quote
we can use but what if we have multiple records with same price?
we should not do hard code.

N.Rajesh kumar
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
17586 Posts

Posted - 03/06/2014 :  01:23:13  Show Profile  Reply with Quote
use get the top price in derived table and JOIN to your main table

select *
from   yourtable t
       inner join
       (
           select top 1 price from yourtable order by price desc
       ) p on t.price = p.price



KH
Time is always against us

Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
17586 Posts

Posted - 03/06/2014 :  01:25:37  Show Profile  Reply with Quote
alternative method. use dense_rank() http://technet.microsoft.com/en-us/library/ms173825.aspx


KH
Time is always against us

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000