Jump to content

Recommended Posts

Hi All

 

My database is set up with 3 tables with the following column names and a samle set of data

 

nsr_entrants

 

|entrant_id | Name |

--------------------

|      1      |  Jon  |

|      2      |  Ken  |

|      3      |  Bob  |

 

 

nsr_bibno:

 

|entrant_id | bibno |

--------------------

|    1        |  100  |

|    2        |  200  |

 

 

nsr_scores:

 

| entrant_id | score |

---------------------

|      1      |  20  |

|      3      |  20  |

 

 

 

What i need to do is find the entrants (listed within the nsr_entrants table) who have a bib number registered in the nsr_bibno table, but who dont have a score registered in the nsr_scores table.

 

So in the above example, i would want the statement to pick out Ken (id=2) because that person has a bib number registered, but has no score registered.

 

I know how to join the tables seperatley, but im not sure how to do both in one go. My attempts so far have failed.

 

Im using mySQL version 5.0.45

 

Anyone able to help me out?

Link to comment
https://forums.phpfreaks.com/topic/89644-complex-join-statement/
Share on other sites

I would imagine something like this:

 

SELECT

            ne.*

  FROM

            nsr_entrants ne

    JOIN

            nsr_bibno nb

      ON

            nb.entrant_id = ne.entrant_id

LEFT JOIN

            nsr_scores ns

      ON

            ns.entrant_id = ne.entrant_id

WHERE

            ns.entrant_id IS NULL

;

 

Based on your sample data, the above query should show only Ken (# 2).

 

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.