Reputation: 32331
I have a table , from which i am getting max value , but incase of no records how to get value as 0 instead of null
This is my table
CREATE TABLE IF NOT EXISTS `video_details` (
`video_id` int(6) NOT NULL auto_increment COMMENT 'Auto Generated key',
`video_name` varchar(50) default NULL,
PRIMARY KEY (`video_id`)
) ENGINE=InnoDB AUTO_INCREMENT=382 DEFAULT CHARSET=utf8;
This is my query
select max(vd.video_id) as count from video_details vd;
Upvotes: 1
Views: 29
Reputation: 69460
use ifnull
select ifnull(max(vd.video_id),0) as count from video_details vd;
Upvotes: 2
Reputation: 48197
use COALESCE
select COALESCE (max(vd.video_id),0) as count
from video_details vd;
Upvotes: 2