Click here to Skip to main content
15,899,632 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to get last row of a table in SQL.
if one row in table not show 1st row.
only show empty value


What I have tried:

$result2 = mysql_query("SELECT  max(result_date) as result_date FROM attends where result_date_only='$datefrom' and st_id=$st_id");


this query show ... one row in table show max row and min row is same
Posted
Updated 19-Dec-17 10:20am
v2
Comments
RossMW 18-Dec-17 14:02pm    
I appreciate english may not be your native language, but Im afraid I struggle to understand exactly what you are trying to do, and what the problem or issue is. Can you please elaborate

1 solution

You asked how to show a row but then your sql is only getting a single value. Assuming you want the max date from the table or NULL if there is only a single record one way to do it is like this:
SQL
IF (SELECT COUNT(*) FROM table) <= 1
  BEGIN
    SELECT NULL AS myDate
  END
ELSE
  BEGIN
    SELECT MAX(date_field) AS myDate
    FROM table
  END


Put this in a stored procedure, don't try to do it as inline sql in php.


Quote:
one row in table show max row and min row is same
Which is perfectly fine because that IS the correct data.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900