Jump to content

selection logic with lookup table


erewash

Recommended Posts

I'm sure this is really basic and it is just a matter of getting the JOIN right, but my brain is addled by trying to work out the logic;

I need to run a selection, and read data into an array, from two simple tables, plus one lookup table. So, each 'people' record will have one or more addresses, and each record _may_ have one or many 'prog' records.

[code]
$sql = "SELECT pe.people_id, pe.loginname, pe.password, ..... ,
                    addr.institution, addr.department, ..... ,
                    lk.pprog_id
            FROM (my_people AS pe LEFT JOIN my_address AS addr ON pe.people_id=addr.people_id)
                LEFT JOIN my_people_prog AS lk ON pe.people_id=lk.ppeople_id
                  WHERE surname <> '' ";
                                      [plus various other selection criteria posted from form]
[/code]

The first part of the selection - against people and address - works fine, but introducing the 'prog' gives me one row for each 'prog' it finds that matches, which is embarrassing.... could someone please advise??

Next scary step will be to enable the selection on the basis of the descriptor, rather than the code, for the 'prog' record - I guess this is best achieved through clever use of drop-downs on the selection form....

Thank you very much.
Link to comment
Share on other sites

Okay, not meaning to waste peoples' time - I find that ORDER BY at the end of the select seems to do the job for me now - had been putting it in the wrong place! A case of tying myself in knots... but is there a neater way to achieve what I am after?

Thank you!
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.