I'm working on this file upload tinyurl like thing and have some problems with one mysql query. There are 2 tables with "id"s and I want to count all data and views in those tables with a mysql query. But when there are no records for the specified user_id in one of the tables the views is set to NULL and I want an integer. I've looked at CAST and CONVERT but can't seem to get it to work.
This is my current query:
SELECT datax + datay AS data, viewsx + viewsy as views FROM
(SELECT COUNT(*) AS datax, SUM(views) as viewsx FROM `data_id_custom` WHERE `user_id` = 1) as x,
(SELECT COUNT(*) AS datay, SUM(views) as viewsy FROM `data_id` WHERE `user_id` = 1) as y