SQL AND operator not working properly

Posted by Chandana De Silva on Stack Overflow See other posts from Stack Overflow or by Chandana De Silva
Published on 2011-01-09T08:28:13Z Indexed on 2011/01/09 9:53 UTC
Read the original article Hit count: 206

Filed under:

I have following two tables

LandParcels Table

Blockid ParcelNo storPri
======= ======== =======
52000105   3      State
52000105   4      Private
52000105   5      State

Actions Table

Blockid ParcelNo ActionTaken
======= ======== ===========
52000105   3      Received
52000105   3      Send to Computer
52000105   4      Received
52000105   5      Received

I want to find the records Received but not Send to Computer

Here is my query

select 
    l.blockid, l.parcelno 
from 
    landparcels l 
left join 
    actions ac on l.blockid = ac.blockid and l.parcelno = ac.parcelno 
where 
    ac.actiontaken = 'Received' 
    and ac.actiontaken <> 'Send to Computer'  
    and ac.blockid = 52000105 

The result is

Blockid ParcelNo 
======= ======== 
52000105   3
52000105   4
52000105   5

I want ParcelNo 4 and 5

© Stack Overflow or respective owner

Related posts about sql