1

I have three rows in a table. I'm trying to get and display the last row of my table and, instead, its always displaying the result of the middle row.

I have tried to used the "DESC" or "DESC LIMIT 1" but still its not working.

Example:

I have a 3 rows in my table of tbldata.

0:5

0:10

0:15

The query for this:

$result = mysql_query("SELECT fldBldgName, fldTimestamp,   
MIN(fldTotalDuration)fldTotalDuration   
FROM tbldata    
WHERE  fldNetname = '".$network."'   
AND fldBldgName = '".$bldg[$i]."'    
AND  fldWeek = '".$week."'   
AND fldMonth = '".$month."'   
GROUP BY fldBldgName   
ORDER BY  fldBldgName,fldTimestamp, fldTotalDuration DESC");

I already tried also the ID to order by but still its not working. I tried the timestamp, but still its not working.

The result for that query is always the "0:10", the correct output should be "0:15".

But then if I have 2 rows only:

0:5

0:10

the result is : 0:10 which is correct

And so, I also tried it to manually query it in phpmyadmin, but it still does not display the last row.

3
  • try SELECT * FROM tbl ORDER BY id DESC Whats the output? Commented Aug 18, 2013 at 13:08
  • @T_01..the result are : 0:15, 0:10, 0:5 Commented Aug 18, 2013 at 13:12
  • @T_01...yeh ...oh yeah! thanks! but why its working like that? is there a different with your query in my query? Commented Aug 18, 2013 at 13:16

1 Answer 1

3

Assuming you have an id field with AUTO_INCREMENT set.

Then try this

SELECT * FROM tbl ORDER BY id DESC LIMIT 1;

Your use of MIN(fldTotalDuration) and GROUP BY was totally confusing the result you were after.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.