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

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -