Q:

Simplify two MySQL queries by merging them into 1?

I have two MySQL queries which are very similiar however they return a COUNT() upon a specific WHERE clause (type), so I was wondering if they could be merged into 1 query seeing as only the WHERE clause (type) differenciates the two?
Query 1:
SELECT COUNT(referral_id) AS in_count
FROM   referrals
WHERE  author = '{$author}'
       AND type = 'in'
       AND ip_address = '{$ip_address}'
LIMIT  1 

Query 2:
SELECT COUNT(referral_id) AS out_count
FROM   referrals
WHERE  author = '{$author}'
       AND type = 'out'
       AND ip_address = '{$ip_address}'
LIMIT  1 

All help is greatly appreciated :B

A:

SELECT SUM(IF(type='in',1,0)) as in_count, 
       SUM(IF(type='out',1,0)) as out_count
FROM   referrals
WHERE  author = '{$author}' AND
       ip_address = '{$ip_address}'
LIMIT  1 

