how to select only 1 data out of few?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
mit
Forum Commoner
Posts: 32
Joined: Mon Sep 15, 2008 6:37 am

how to select only 1 data out of few?

Post by mit »

bank remarking number 1 2009-01-05 18:16:29
bank remarking number 2 2009-01-05 18:16:31
bank remarking number 3 2009-01-05 18:16:32
bank remarking number 4 2009-01-05 18:16:33

i need to select only the last bank which is having remarking number4 and is the latest data that inserted into data base, i dont want to use time for this matter is there any other way?.
thx
mit
Forum Commoner
Posts: 32
Joined: Mon Sep 15, 2008 6:37 am

Re: how to select only 1 data out of few?

Post by mit »

SELECT `remark` FROM `remarks` WHERE `project_name` = 'bank' this is showing all, whereas i need the last remark
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: how to select only 1 data out of few?

Post by VladSun »

+
[sql]ORDER BY     remarking_number DESCLIMIT    1[/sql]
There are 10 types of people in this world, those who understand binary and those who don't
jason.carter
Forum Commoner
Posts: 35
Joined: Sat Jan 10, 2009 10:05 am

Re: how to select only 1 data out of few?

Post by jason.carter »

Try a sub query if you want

SELECT remarks FROM remarks WHERE remark_id = (SELECT max(remark_id) FROM remarks)

If you have a remark_id then it is fairly easy to pull the latest row.
Post Reply