![]() |
MySQL three table join - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: MySQL three table join (/showthread.php?tid=90406) |
MySQL three table join - bobw - 03-13-2024 I'm starting to tear my hair out over this one - well I would if I had any to begin with! I've three tables in my database that I wish to query. Two of the tables, members and helpers, are data with the third, membershelpers, being a link table. The database isn't normalised, may be a problem, but this worked in CI3 and the database schema hasn't changed. Code: members{ Code: members.id I'm starting from a members.id value, passed in to a binding query via :id: Code: SELECT h.membership_number, h.given_name, h.family_name, FROM helpers AS h JOIN membershelpers mh ON mh.helper_id = p.id WHERE mh.contender_id = :id: ORDER BY h.family_name ASC, h.given_name ASC What I'm wanting in the above query is to also have the members.id value so I can create a link with it to jump to a page displaying info about that member. The CI3 code was Code: $h = new Helper(); I've got the feeling I've gone down the wrong rabbit hole Typical! Figured it out. Added (SELECT id FROM members m WHERE m.given_name = h.given_name AND m.family_name = h.family_name) AS helper_id to the fields being selected. |