PDA

View Full Version : Max value of one Identity filed



faramarz_s
شنبه 23 اسفند 1382, 11:27 صبح
جهت انتخاب بزرگترین مقدار یعنی 7 برای Id چه تغییری باید در کویری بدهم؟
http://doost.europe.webmatrixhosting.net/sql/max01.gif
:oops:

شنبه 23 اسفند 1382, 13:23 عصر
سلام

Group by subject را بردار درست میشه.

faramarz_s
شنبه 23 اسفند 1382, 16:08 عصر
Server: Msg 8118, Level 16, State 1, Line 1
Column 'tblNews.subject' is invalid in the select list because it is not contained in an aggregate function and there is no GROUP BY clause.

:P
الزاما باید باشد :flower:

vadood
شنبه 23 اسفند 1382, 16:58 عصر
از top و order by استفاده کن

faramarz_s
شنبه 23 اسفند 1382, 20:39 عصر
از Order by استفاده کردم منتها یک رکورد نمی دهد باDesc توانستم بر اساس بزرگترین سورت کنم.فقط همین!
top را باید در مورد ش تحقیق کنم چون تجربه استفاده از آنرا ندارم. :!:

faramarz_s
شنبه 23 اسفند 1382, 21:12 عصر
The TOP clause limits the number of rows returned in the result set.

TOP n [PERCENT]

n specifies how many rows are returned. If PERCENT is not specified, n is the number of rows to return. If PERCENT is specified, n is the percentage of the result set rows to return:

TOP 120 /*Return the top 120 rows of the result set. */
TOP 15 PERCENT /* Return the top 15% of the result set. */.

If a SELECT statement that includes TOP also has an ORDER BY clause, the rows to be returned are selected from the ordered result set. The entire result set is built in the specified order and the top n rows in the ordered result set are returned.


http://doost.europe.webmatrixhosting.net/sql/top01.gif
یک نمونه بفرمایید.Please

شنبه 23 اسفند 1382, 22:39 عصر
سلام

ببخشید من به فیلد subject دقت نکردم اینو نگاه کن حتما درسته :mrgreen:


select NewsId , subject
from tblNews
where
NewsId in(select Max(NewsId) from tblNews)

vadood
یک شنبه 24 اسفند 1382, 10:51 صبح
SELECT TOP 1 field1, field2, ... FROM table

faramarz_s
یک شنبه 24 اسفند 1382, 20:55 عصر
select NewsId , subject
from tblNews
where
NewsId in(select Max(NewsId) from tblNews)