php - If there is no value in the table, then query should return 0 -


this query

select (max(booking_id),0) bookingid booking; 

if there no value in table, query should return 0. how this??

two alternatives:

  1. using ifnull:

    select ifnull(max(booking_id),0)) bookingid booking; 
  2. using coalesce:

    select coalesce(max(booking_id),0)) bookingid booking; 

explanation:

ifnull can used in mysql. coalesce can used in rdbmss. coalesce returns first parameter in list not null.


Comments