I have a question.
My database table is something like this:
| ID | Name | Value | param |
| 1 | Michael | 290 | X |
| 2 | John | 300 | X |
| 3 | Michael | 270 | X |
| 4 | John | 280 | X |
| 5 | Michael | 256 | Y |
| 6 | Michael | 230 | Y |
¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨
So, I want to use a form to select the latest rows with different param but equal name.
For example, if I search for “Michael”, I want to use PHP to show the latest value for the param X and the latest value for the param Y (returning 2 rows).
Michael: Param Y: 230
Michael: Param X: 270
And if I search for “John” I get:
John: Param X: 280.
The code
$sql = "SELECT * FROM thetable WHERE name = 'Michael' ORDER BY ID DESC";
$result = mysql_query($sql);
Now I just want for it to select only the latest rows with different param.
Thanks in advance.
Are the approaches listed won’t work with n variable “params”. I think something similar may work:
See http://sqlfiddle.com/#!2/64dc4/11