Ti suggerisco fortemente di normalizzare i tuoi dati, come hanno raccomandato altri.
In base alla tua struttura attuale, puoi usare FIND_IN_SET per ottenere il risultato che vuoi:
SELECT M.id, M.name, COUNT(*) total FROM members M INNER JOIN videos V ON FIND_IN_SET(M.name,V.members) > 0 GROUP BY M.name ORDER BY M.id Eseguendo questo sui tuoi dati di esempio si ottiene:
| id | name | total | |----|-------|-------| | 1 | Tom | 2 | | 2 | Bob | 2 | | 3 | Zack | 3 | | 4 | Dan | 3 | | 5 | Casey | 2 | Una lettura obbligatoria
Is storing a delimited list in a database column really that bad?
Altro
Ecco come apparirebbe la tua tabella videos se normalizzassi i tuoi dati:
videos
id member_id