mysql: how to query when id in another table record's field -
this question has answer here:
- query multiple values in column 4 answers
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
Post a Comment