SQL query: get the last row depends on the field
I have a new problem now. Its all about displaying the result in my database.
Scenario: I was trying to display the last data in my database
[fldBldgName and fldTotalDuration]. So, assuming that I have a two data
under the fldBldgName and fldTotalDuration.
Example:
fldBldgName fldTotalDuration
bldg1 0:2
bldg1 0:32
bldg1 0:40
bldg1 0:45
bldg2 0:10
bldg2 0:12
As you can see under the fldBldgName have a same building name yet
different fldTotalDuration...
I have a problem for displaying it, because in my query the result is
fldBldgName fldTotalDuration
bldg1 0:2
bldg2 0:10
this is wrong...
the correct is
fldBldgName fldTotalDuration
bldg1 0:45
bldg2 0:12
Here's my query:
SELECT * FROM tbldata WHERE fldNetname = '".$get_radio."'
AND fldMonth = '".$get_month."' AND fldWeek = '".$get_week. "'
GROUP BY fldBldgName
ORDER BY id, fldBldgName, fldTotalDuration DESC
Even the ASC is not working....If I include a "DESC LIMIT 1" it will just
display only one....I need to display, all unique fldBldgName and the
corresponding/last row of fldTotalDuration..
Thanks for help.
No comments:
Post a Comment