Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

mysql single query for two tables

Posted on 2014-02-25
4
Medium Priority
?
271 Views
Last Modified: 2014-02-28
how can i combine the following into one query.
the two tables are unrelated lists of IP addresses, one a whitelist and one a blacklist of IP addresses.   I want to to return nothing IF the IP address  IS ANYWHERE in the whitelist
Thus whitelist takes precedence in the logic, over the blacklist.

SELECT blacklist.* FROM blacklist, whitelist  
         WHERE   blacklist.IPaddress='$IPaddress'
             BUT NULL RESULTS     IF     COUNT(whitelist.IPaddress='$IPaddress')>0

i need to do this within one query due to the way i'm executing it via a single shell command.

thanks
0
Comment
Question by:willsherwood
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 35

Accepted Solution

by:
Dan Craciun earned 2000 total points
ID: 39887322
What's wrong with And?
SELECT blacklist.* FROM blacklist, whitelist  
         WHERE   blacklist.IPaddress='$IPaddress' AND COUNT(whitelist.IPaddress='$IPaddress')=0

Open in new window


HTH,
Dan
0
 

Author Closing Comment

by:willsherwood
ID: 39887427
i guess nothing's wrong with "thank you" too
0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39887448
Glad I could help!
0
 

Author Comment

by:willsherwood
ID: 39896350
please help further - it turns out the COUNT cannot be used in a WHERE clause
"illegal use of GROUP function"

back to original question:   how to include two tables as desired above?
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question