Jump to content

Multiple joins


lional

Recommended Posts

Is it possible to do a join on more than one table eg

$query = "SELECT * from personal_details JOIN ra_card_1 ON personal_details.member_no = ra_card_1.member_no AND form1.form1 ON personal_details.member_no = form.member_no WHERE form1.chapter_no = '$chapnum AND form1.form1 = 0'";

What I am trying to do is to select the member from personal_details table where that member is a member of a specific chapter that is specified in ra_card_1 table, but I also want to check if they have submitted their information and that is stored in the form1 table

Is this possible and if it is, please give me some pointers on how to do it

Thanks

Lional
Link to comment
https://forums.phpfreaks.com/topic/29213-multiple-joins/
Share on other sites

You need a JOIN ON statement for every table except the first. Also, I couldn't tell from your example where form1 fit in so you'll have to use my example to work it in.
[code]
SELECT *
FROM personal_details AS pd
JOIN ra_card_1 AS card ON personal_details.member_no = ra_card_1.member_no
JOIN form AS f ON pd.member_no = f.member_no
JOIN form1 AS f1 ON (this should tie back to the pd or form table but I dont know how)
WHERE form1.chapter_no = '$chapnum AND form1.form1 = 0'

[/code]
(technically, MySQL will allow you to declare multiple tables in the FROM statement but it will choke when you try to add joins on anything but the last table defined in the FROM clause)
Link to comment
https://forums.phpfreaks.com/topic/29213-multiple-joins/#findComment-134111
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.