Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
Shendemiar
Forum Contributor
Posts: 404 Joined: Thu Jan 08, 2004 8:28 am
Post
by Shendemiar » Mon Nov 28, 2005 9:30 pm
A table can have several instances of data, one row for each date when its added, like
Code: Select all
name - size - date
------------------------------
kana - 1 - 1
kana - 2 - 2
kana - 2 - 4
sika - 3 - 2
koira - 1 - 1
I want to select one instance of each, the latest (with newest date). The date is represented as 2005-11-29.
Can it be done with one query (with no subqueries)?
infolock
DevNet Resident
Posts: 1708 Joined: Wed Sep 25, 2002 7:47 pm
Post
by infolock » Mon Nov 28, 2005 9:38 pm
i'm sorry.. but in order to help, you might want to be a little more descriptive. all i can gather is you want to grab a field for a particular date, but for what field and how you determine if it's the right field + date .. well, i have no idea. so, could ya give us a little more info
Shendemiar
Forum Contributor
Posts: 404 Joined: Thu Jan 08, 2004 8:28 am
Post
by Shendemiar » Mon Nov 28, 2005 10:08 pm
I want one row for each name with the latest date, and the size on that date.
n00b Saibot
DevNet Resident
Posts: 1452 Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:
Post
by n00b Saibot » Tue Nov 29, 2005 1:46 am
does this work, tho I wouldn't expect
Code: Select all
SELECT DISTINCT `name`, `size`, `date` FROM `tbl` WHERE `date`>'{$reqd_date}'
BTW, where were you these days