mysql - exclude multiple records

Hi All,

I need to list all the information from a database containing a number of tables but include only the information where the serial number from the wasp table isnt null and then exclude the information from site1, site2 and site3.

The sql I have is below but I cant get it to return the correct results.

Can anyone help me format the sql query


select p.`site` as SITE, p.`net0mac` as MAC_ADDRESS, mac_table.position as DESK_POSITION, wasp.location as WASP_REFERENCE, p.`serial` as SERIAL_NUMBER, p.`halfile` as HAL_FILENAME
from pc_details p 
left join mac_table on p.net0mac=mac_table.macaddress
left join wasp on p.serial=wasp.serial_no
where wasp.serial_no <> '' and p.site != 'site1' or p.site != 'site2' or p.site != 'site3'
order by p.site,mac_table.position

Open in new window

LVL 19
joolsSenior Systems AdministratorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RemcovCCommented:
You might wanna try something like this:
select p.`site` as SITE, p.`net0mac` as MAC_ADDRESS, mac_table.position as DESK_POSITION, wasp.location as WASP_REFERENCE, p.`serial` as SERIAL_NUMBER, p.`halfile` as HAL_FILENAME
from pc_details p 
left join mac_table on p.net0mac=mac_table.macaddress
left join wasp on p.serial=wasp.serial_no
where wasp.serial_no <> '' and p.site != 'site1' AND p.site != 'site2' AND p.site != 'site3'
order by p.site,mac_table.position
 

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
racekCommented:

select p.`site` as SITE, p.`net0mac` as MAC_ADDRESS, 
       m.position as DESK_POSITION, w.location as WASP_REFERENCE, 
       p.`serial` as SERIAL_NUMBER, p.`halfile` as HAL_FILENAME
from pc_details p 
left join mac_table m
      on  p.net0mac= m.macaddress 
      and p.site NOT IN ('site1','site2','site3')
join wasp w on p.serial=w.serial_no AND w.serial_no <> ''
order by p.site,m.position;

Open in new window

0
TKorhanCommented:
And you can try this :

select p.`site` as SITE, p.`net0mac` as MAC_ADDRESS, mac_table.position as DESK_POSITION, wasp.location as WASP_REFERENCE, p.`serial` as SERIAL_NUMBER, p.`halfile` as HAL_FILENAME
from pc_details p 
left join mac_table on p.net0mac=mac_table.macaddress
left join wasp on p.serial=wasp.serial_no
where wasp.serial_no <> '' and (p.site != 'site1' or p.site != 'site2' or p.site != 'site3')
order by p.site,mac_table.position

Open in new window

0
racekCommented:
WHY....left join wasp on p.serial=wasp.serial_no
where wasp.serial_no <> '' ... ???

it is same thing as:

join wasp on p.serial=wasp.serial_no AND wasp.serial_no <> ''
0
joolsSenior Systems AdministratorAuthor Commented:
Thx Chaps, RemcovC had the first response but I also liked the other answers, I was wondering about using NOT IN so thx for the example.
Looks like my logic (AND/OR) was flawed.... again!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.