473,468 Members | 1,371 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Select last 3 items in ascending order

Hi there,

I'm not sure how to select the last 3 items in ascending order.

This does the trick in descending order:

select * from user_menu_main
where deleted = 0 and hidden = 0
order by date desc
limit 3

Your comments would be very much appreciated.

Cheers,
Nick
Aug 2 '06 #1
5 9968

Nick Weisser wrote:
Hi there,

I'm not sure how to select the last 3 items in ascending order.

This does the trick in descending order:

select * from user_menu_main
where deleted = 0 and hidden = 0
order by date desc
limit 3

Your comments would be very much appreciated.

Cheers,
Nick
i'm guessing that 'desc' bit's got something to do with it

Aug 2 '06 #2
strawberry wrote:
i'm guessing that 'desc' bit's got something to do with it
But this will not select the 3 last items in ascending order, but the
first 3!
Aug 2 '06 #3
"Nick Weisser" <ni**@nospam.freemails.chwrote in message
news:44**********@news.bluewin.ch...
Hi there,

I'm not sure how to select the last 3 items in ascending order.

This does the trick in descending order:

select * from user_menu_main
where deleted = 0 and hidden = 0
order by date desc
limit 3

Your comments would be very much appreciated.
That problem is a natural for a temporary table.

create temporary table tmp
select * from user_menu_main
where deleted = 0 and hidden = 0
order by date desc
limit 3;

select * from tmp
order by date desc;

Thomas Bartkus


Aug 2 '06 #4

Thomas Bartkus wrote:
"Nick Weisser" <ni**@nospam.freemails.chwrote in message
news:44**********@news.bluewin.ch...
Hi there,

I'm not sure how to select the last 3 items in ascending order.

This does the trick in descending order:

select * from user_menu_main
where deleted = 0 and hidden = 0
order by date desc
limit 3

Your comments would be very much appreciated.

That problem is a natural for a temporary table.

create temporary table tmp
select * from user_menu_main
where deleted = 0 and hidden = 0
order by date desc
limit 3;

select * from tmp
order by date desc;

Thomas Bartkus
I see, you want to limit your select to last three items of a list, but
have those items listed in the ordinary order. Well Thomas's solution
is probably the most straightfoward, although (depending on your
version) you don't actually need to create the temporary table:

(untested)

select * from (
select * from user_menu_main
where deleted = 0 and hidden = 0
order by date desc
limit 3) tmp
order by date asc;

Aug 2 '06 #5
"strawberry" <za*******@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
>
Thomas Bartkus wrote:
"Nick Weisser" <ni**@nospam.freemails.chwrote in message
news:44**********@news.bluewin.ch...
Hi there,
>
I'm not sure how to select the last 3 items in ascending order.
>
This does the trick in descending order:
>
select * from user_menu_main
where deleted = 0 and hidden = 0
order by date desc
limit 3
>
Your comments would be very much appreciated.
>
That problem is a natural for a temporary table.

create temporary table tmp
select * from user_menu_main
where deleted = 0 and hidden = 0
order by date desc
limit 3;

select * from tmp
order by date desc;

Thomas Bartkus

I see, you want to limit your select to last three items of a list, but
have those items listed in the ordinary order. Well Thomas's solution
is probably the most straightfoward, although (depending on your
version) you don't actually need to create the temporary table:
... you don't actually need to create the temporary table:
On the other hand - there ain't no reason not to ;-)

That subquery you show, for instance, uses a temporary table behind the
scenes.
Thomas Bartkus
Aug 2 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Bob Bedford | last post by:
I've a site where companies add their article. I'de like to provide a "lasts articles" table. By this, I'll show last articles inserted. But I won't always the same articles at any refresh....
4
by: headware | last post by:
I have a <select> control that contains many entries. It allows the user to multi-select a group of them, click a button, and store the selected data in a database. Normally they do this starting...
8
by: Jean | last post by:
Hello all, I have the following data, that was queried and sorted to columns PROBLEM_ID and then by STATUSDATE (ascending): STATUS_ID STATUSDATE PROBLEM_ID --------- ---------- ...
1
by: Prasad Karunakaran | last post by:
I am using the C# DirectoryEntry class to retrieve the Properties of an user object in the Active Directory. I need to get the First Name and Last Name as properties. I know it is not supported...
2
by: Joe Fallon | last post by:
I have 2 listboxes on a Web Form. As I move an item from 1 to the other it shows up at the end of the list. How can I sort the list that just got the new item added to it so it is in alphabetical...
1
by: ralf321 | last post by:
hello! i have this xml: <object> <node meta="27" > <data meta="13" changed="2005-09-05 16:16:43">a</data> <data meta="14" changed="2005-11-06 19:26:49">b</data> <data meta="15" ...
1
by: polocar | last post by:
Hi, I'm using Visual C# 2005 (part of Visual Studio 2005 Professional Edition), and I have the following problem: I populate a ListView object with several items, and at the end of this process I...
1
by: JAnn81 | last post by:
I have a combo box created using xaml. I bind the item source to a xml document. <Items> <Item> <Name>David</Name> <Age>20</Age> </Item> <Item> <Name>Marcus</Name> <Age>25</Age>
7
by: kwstriker299 | last post by:
Today in class, my professor posed an interesting question for us to think about before our next class. If you insert items that are in ascending order into a binary search tree, then you will build...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.