Jump to content

selecting records with join


redneonrt

Recommended Posts

I have 3 tables im working with

 

sab_merc (job table)

-id

-username

-service

-job_desc

 

Users (user table)

-id

-username

-other misc info

 

onjob_sab (theis in the x-ref table in a many to many relationship)

-user_id

-job_id

 

 

select  from onjob_sab left join sab_merc on(onjob_sab.user_id = sab_merc.id) where (onjob_sab.user_id != '1')

 

what I get from this query is all the open jobs that user 1 is not part of.

 

Now since multiple people can can be on multiple jobs I get a query that repeats the jobs for each users on them

2     chris     sextreme69     AIM     Stryker_     http://www.kingsofchaos.com/stats.php?id=3012255     Elves     1     Gold     500000     0           11.13.05     1131940811     open     2     1
2     chris     sextreme69     AIM     Stryker_     http://www.kingsofchaos.com/stats.php?id=3012255     Elves     1     Gold     500000     0           11.13.05     1131940811     open     2     3
4     workwarnings     testee     MSN     Steeringwhell     http://www.kingsofchaos.com/stats.php?id=3009074     Elves     5     Gold     78552     0           11.15.05     1132116959     open     4     4
4     workwarnings     testee     MSN     Steeringwhell     http://www.kingsofchaos.com/stats.php?id=3009074     Elves     5     Gold     78552     0           11.15.05     1132116959     open     4     5

 

All I really want from this query is to fin all jobs that user 1 is not assiged too and them display them in a "while loop" using php.

 

So in the example you can see that there is really only 2 jobs available that user 1 is not assiged too, but they get repeated since there is already other users on those jobs.

 

Hope this makes sense

 

Thanks in advance,

Chris

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.