Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Posts
    419
    Thanks
    18
    Thanked 2 Times in 2 Posts

    a join conditional for no data

    sorry.... I know I just posted, but I have an other question...

    Is there a conditional to let a query pull results even if one of the joins pulls no result. Right now, if nothing is in table 4 for that entry, I get a blank page. But if it exists, the information will pull. I want to add the table4 info only if it exists and not lose the rest.

    I have:
    Code:
    SELECT table1.*, table2.*, table3.*, table4.*
    FROM table1
    JOIN table2 ON table1.id = table2.id 
    JOIN table3 ON table3.id = table2.id
    JOIN table4 ON table4.id = table2.id AND table4.part_id = 1
    
    WHERE table1.id = $id

  • #2
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,982
    Thanks
    120
    Thanked 76 Times in 76 Posts
    Code:
    SELECT table1.*, table2.*, table3.*, table4.*
    FROM table1
    JOIN table2 ON table1.id = table2.id 
    JOIN table3 ON table3.id = table2.id
    LEFT JOIN table4 ON table4.id = table2.id AND table4.part_id = 1
    
    WHERE table1.id = $id
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •