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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.