Solved

mysql single query for two tables

Posted on 2014-02-25
4
263 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
  • 2
  • 2
4 Comments
 
LVL 34

Accepted Solution

by:
Dan Craciun earned 500 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 34

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Introduction In this article, I will by showing a nice little trick for MySQL similar to that of my previous EE Article for SQLite (http://www.sqlite.org/), A SQLite Tidbit: Quick Numbers Table Generation (http://www.experts-exchange.com/A_3570.htm…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now