473,398 Members | 2,393 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Top 5 rows

Hi,
How to get top 5 newly entered rows in a table. i am trying with "select top 5 * from Test" but its giving old entries.if i want new entries how?
Dec 15 '06 #1
7 10978
if u have an date col under this table then..
select top 5 * from test order by desc of date col
Dec 15 '06 #2
if u have an date col under this table then..
select top 5 * from test order by desc of date col
Hi Vinay,
i have date col, but i am joining with another table. i am using where clause for date its not giving top 5 rows
Dec 15 '06 #3
almaz
168 Expert 100+
Hi Vinay,
i have date col, but i am joining with another table. i am using where clause for date its not giving top 5 rows
Once again: There is no term "order of records in database".
If you want to get records with some order, you must provide an ORDER BY clause. Without ORDER BY clause select returns unordered list of records, that occasionally may be returned in the order you want. If you don't have a field that you can use to determine latest records - you wouldn't be able to get the last records in consistent manner. If you do have such a field - use ORDER BY [this field] DESC/ASC and select top records.
If you want to get more information about your particular case - provide us with DDL (data definition language: scripts for table creations) scripts and queries you're trying to run
Dec 15 '06 #4
willakawill
1,646 1GB
Hi Vinay,
i have date col, but i am joining with another table. i am using where clause for date its not giving top 5 rows
Hi
is there an auto number id field for this table?
Dec 15 '06 #5
Hi
is there an auto number id field for this table?

yes it is there "itemid". this is my query

Select ModuleId,
ItemId,
Content,
CreatedByUser,
CreatedDate
from Test with (nolock)
Left Outer Join Users On Test.CreatedByUser = Users.UserId
Where CreatedDate in (Select Top 5 CreatedDate from Test Order By CreatedDate Desc) And ModuleId = @ModuleId

with this @ModuleId i have so many rows in the table.but its returning always 3rows only .
Dec 15 '06 #6
cyberdwarf
218 Expert 100+
Try adding:-

Expand|Select|Wrap|Line Numbers
  1. Select top 5.....
at the top of your query and....
Expand|Select|Wrap|Line Numbers
  1. order by ItemId Desc
at the bottom.

HTH

Steve
Dec 15 '06 #7
Try adding:-

Expand|Select|Wrap|Line Numbers
  1. Select top 5.....
at the top of your query and....
Expand|Select|Wrap|Line Numbers
  1. order by ItemId Desc
at the bottom.

HTH

Steve

thank u i solved .....
Dec 15 '06 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Egor Shipovalov | last post by:
I'm implementing paging through search results using cursors. Is there a better way to know total number of rows under a cursor than running a separate COUNT(*) query? I think PostgreSQL is bound...
6
by: dddddddd2444444 | last post by:
Hi,please help... It works fine when I define a 2-D array like char code. But it won't work when I try to define the array dynamically using a function. It just crashes. Does anyone know why?...
7
by: GaryB | last post by:
I have an untyped datatable that has financial numbers and controls that were populated by code (not a simple fill from a DA). Now I want to insert subtotals into it. I wrote a sub to do so that...
0
by: Subba Rao via DotNetMonster.com | last post by:
---------------------------HTML---------------------------------------- <html> <head> <title>:: DHTML Table Demo ::</title> <script langauge="javascript" src="InterchangeRows.js"></script>...
12
by: Graham Blandford | last post by:
Hi all, Would someone be able to tell me the most 'graceful' way of removing unwanted rows from a dataset based on a condition prior to update? OR, resetting the rows all to unchanged after they...
68
by: Martin Joergensen | last post by:
Hi, I have some files which has the following content: 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0
11
by: jimstruckster | last post by:
I have a table with 10 rows, I want all rows except for the first to be hidden when the page first opens up. If the user puts a value in a text box in the first row then I want the second row to...
3
by: Niyazi | last post by:
Hi all, I have a dataTable that contains nearly 38400 rows. In the dataTable consist of 3 column. column 1 Name: MUHNO column 2 Name: HESNO Column 3 Name: BALANCE Let me give you some...
0
by: rn5a | last post by:
All the rows in a DataGrid are accompanied by a CheckBox. When a user checks the rows & clicks a Button, the checked rows get deleted. For e.g. assume that the DataGrid displays 10 rows. A user...
3
by: nigelesquire | last post by:
Please help! I'm trying to clone and delete multiple rows with JavaScript. I need two delete buttons that work...! I only have one for now, but it's not working properly, the output count is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.