Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

mysql single query for two tables

Posted on 2014-02-25
4
Medium Priority
?
274 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 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
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…
Suggested Courses
Course of the Month8 days, 21 hours left to enroll

877 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