I have a piece of code that should return a count of 4, but only comes back with a count of 1. This is my query.
SELECT *, (SELECT COUNT(*) FROM `users` WHERE `user_id` IN (`enc_vs`) AND `rpg_curr_hp` > 0) AS playerCount FROM `encounter` WHERE `enc_id` = 32
The row with enc_id of 32 in encounter
has a group of user id's which are 1,62,12,23 and that is enc_vs. When I do the count with numbers, it works and returns a count of 4. But when I use enc_vs
instead, it comes back as 1.
This would result in:
enc_id | enc_vs | playerCount
32 1,62,12,23 1
The users table looks something like
user_id | rpg_curr_hp
1 55
2 50
3 55
[all the way down to]
12 57
62 55
etc...
The enc_vs
is a string of id's for the users table.
I need it to result in
enc_id | enc_vs | playerCount
32 1,62,12,23 4
assuming that all 4 players have a rpg_curr_hp greater than zero.
EDIT: THIS IS REGARDING A COUNT, NOT A SEARCH FOR COLUMNS.