Combine results of two queries postgres
<p>I have two queries like this:</p>

<pre><code>SELECT project_id, user_ip, count(*) AS Count 
FROM "user" 
WHERE user_ip IS NOT NULL 
GROUP BY user_ip, project_id;

SELECT project_id, user_id, count(*) AS Count 
FROM "user" 
WHERE user_id IS NOT NULL 
GROUP BY user_id, project_id;
</code></pre>

<p>They are all the same except that one returns the users based on IP and other on ID.</p>

<p>Users can have only one of this, so basically if the <code>user_ip</code>  is <code>Null</code> then <code>user_id</code> will have value and the opposite  if <code>user_id</code>  is <code>Null</code>
then <code>user_ip</code> will have value.</p>

<p>So all I want is to make those query one query.</p>

<p>The first query gives this:</p>

<pre><code>project_id | user_ip | Count            
  1        | 1.2.3.4 | 40        
  2        | 1.2.3.5 | 25    
  3        | 1.2.3.6 | 9          
  4        | 1.2.3.7 | 7 
</code></pre>

<p>The second gives this:</p>

<pre><code>project_id | user_id | Count            
  1        |  1234   | 100        
  2        |  4567   | 50    
  3        |  4321   | 49  
</code></pre>

<p>So I want to make only one query that will return this: </p>

<pre><code>project_id | user_id | user_ip | Count            
  1        |  1234   |         | 100 
  1        |         | 1.2.3.4 | 40       
  2        |  4567   |         | 50
  2        |         | 1.2.3.5 | 25     
  3        |  4321   |         | 49 
  3        |         | 1.2.3.6 | 9          
  4        |         | 1.2.3.7 | 7
</code></pre>

<p>I tried to do a left join also I tried to do it with Union but I get ERROR:  <code>UNION types text and integer cannot be matched</code></p>

<pre><code>SELECT project_id, user_ip, count(*) AS Count 
FROM "user" 
WHERE user_ip IS NOT NULL 
GROUP BY user_ip, project_id  
UNION 
SELECT project_id, user_id, count(*) AS Count 
FROM "user" 
WHERE user_id IS NOT NULL GROUP 
BY user_id, project_id;
</code></pre>

<p>Can someone help me to achieve the results that I want? What can I use? </p>