View Single Post
Old 05-03-2009, 09:43 AM   #1 (permalink)
sjaq
The Acquainted
 
sjaq's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 113
Thanks: 11
sjaq is on a distinguished road
Big Grin MySQL query help

Hello again,

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:
Code:
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
Hope this is enough information to get some help

sjaq
sjaq is offline  
Reply With Quote