Page 1 of 1

Sql question

Posted: Mon Nov 28, 2005 9:30 pm
by Shendemiar
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)?

Posted: Mon Nov 28, 2005 9:38 pm
by infolock
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 :?:

Posted: Mon Nov 28, 2005 10:08 pm
by Shendemiar
I want one row for each name with the latest date, and the size on that date.

Posted: Tue Nov 29, 2005 1:46 am
by n00b Saibot
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 :)