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...

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

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.