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

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -