1

This is my query, i'm kinda still getting a hang of mysql joins. i would like to get the count of this query....

SELECT *
FROM `users`
WHERE id = '4'
UNION
SELECT *
FROM `users`
WHERE id IN 
(SELECT group_id 
FROM `users` 
WHERE id = '4')
AND status = '1'
Victor Mbachu
  • 13
  • 1
  • 5

2 Answers2

0

You can count the subquery

  select count(*) from (

  SELECT *
  FROM `users`
  WHERE id = '4'
  UNION
  SELECT *
  FROM `users`
  WHERE id IN 
  (SELECT level 
  FROM `users` 
  WHERE id = '4')
  AND status = '1') t
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
0

I agree with scaisEdge on the code to use. However, what are you trying to do here in the subquery? This seems to look for ID, but you selected 'Level' for the IN statement? Unless LEVEL is the same as ID, it won't do anything.

SELECT *
FROM `users`
WHERE id IN 
(SELECT level 
FROM `users` 
WHERE id = '4')
AND status = '1'
Jim
  • 67
  • 2
  • 10