473,228 Members | 1,820 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,228 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 10968
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.