Solved

mysql single query for two tables

Posted on 2014-02-25
4
267 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
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 …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

776 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