Jump to content

a query to exclude certn fields that match


jeff5656

Recommended Posts

I have 2 table , pts and p_list.  pts has a field called v3 and p_list has a field called mrn.

In the query I want to run all the records from pts but exclude records that match mrn in p_lis table.

I'm sure there is something like JOIN, ut I can't figure it out.

This didn't work

 

$qq = "select * from pts, p_list WHERE pts.v3 != p_list.mrn 
AND pts.v1 like '$lname%' AND pts.user_id = '". $use['id'] ."' ";

 

That didn't exclude records that matched v3 to mrn...

Link to comment
Share on other sites

i think you're looking for a LEFT OUTER JOIN. Basically you want all records in pts EXCEPT the records where (pts.v3 = p_list.mrn), yes? An outer join matches up records then pulls out the ones that missed (on the NULLS).

 

SELECT * FROM pts LEFT OUTER JOIN p_list ON pts.v3 = p_list.mrn WHERE pts.v3 IS NULL

 

I think that's it...  :-[

J

 

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.