mysql: how to query when id in another table record's field -


this question has answer here:

say have 2 tables doctors , patients assume patients has 2 columns: id , name assume doctors has 3 columns: id, npi, patientids each patientids field can have multiple patient's id value. how can query patients belong doctor if given id of doctors table.

i have tried following sql, not return anything

select p.name patients p   p.id in (select patientids doctors d d.id=@id);  

with small data set, fast enough:

select p.name   patients p   join doctors d on d.id=@id , find_in_set(p.id, d.patientids) ; 

but really, commenters have said, want join table mediating relationship between patients , doctors.


Comments

Popular posts from this blog

Why does Go error when trying to marshal this JSON? -

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

python - Pygame. TypeError: 'pygame.Surface' object is not callable -