473,395 Members | 1,680 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

SQL IN syntax. Natural join, maybe?

SELECT ip FROM db1.table1 WHERE ip IN ( SELECT ip_network FROM
db2.table2 WHERE name = <value> )

Basically, the way the data shows up in the first column 'ip' is
x.x.x.x (full ip). However, for ip_network, it is x.x (only the first
two octets).

My question is, are there any ways to do some sort of wildcard search
so that I could match the partial IP from ip_network up to however many
full IPs there are in my first table. It would be a 1:n relationship
(I believe ... I don't have it neccessarily setup w. FKs. This is a
temp. project and this could save me a lot of coding time).

I wouldn't doubt it if it could be accomplished by a JOIN or something
of that nature. I'm just not sure because the two values won't be
exactly equal. Any comments are welcome. Thanks.

Apr 21 '06 #1
4 3053
SELECT ip FROM db1.table1 WHERE ip IN ( SELECT
substring(ip_network,0,6) FROM
db2.table2 WHERE name = <value> )

now, depending on how you store the octets (as left-zero padded or not)
will give you varying results that you may need to resolve using a
programming/scripting language.
I would review the docs on string manipulation.

You could always break the column into octets or just add octet columns
- so that when dealing with IPV6 you won't be getting the wrong
results.

Apr 21 '06 #2
IPv6 wont be an issue for this project. The way they are stored is
simply as you would seem them in modern format (10.1.1.1).

I'm wanting to match one row of '10.1' to all other rows from the
other table that begin with '10.1'.

Apr 21 '06 #3
>SELECT ip FROM db1.table1 WHERE ip IN ( SELECT ip_network FROM
db2.table2 WHERE name = <value> )

Basically, the way the data shows up in the first column 'ip' is
x.x.x.x (full ip). However, for ip_network, it is x.x (only the first
two octets).

My question is, are there any ways to do some sort of wildcard search
so that I could match the partial IP from ip_network up to however many
full IPs there are in my first table. It would be a 1:n relationship
(I believe ... I don't have it neccessarily setup w. FKs. This is a
temp. project and this could save me a lot of coding time).


So compute something suitable from ip that will EXACTLY match
what you have in ip_network. For example, if ip is 192.168.2.3, match
against 192.168 . I suggest:

SELECT ip FROM db1.table1 WHERE substring_index(ip, '.', 2) IN
( SELECT ip_network FROM db2.table2 WHERE name = <value> )

although I have not tested this. Sometimes this sort of thing
involves a nested mess of string functions that search for the position
of things, then use the position to slice off a piece of the string.

Gordon L. Burditt
Apr 21 '06 #4
This seems to be getting closer, however, I still get an error after
the IN.

I'm using MySQL 4.0.1.

Apr 24 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
4
by: MAB | last post by:
Erland Sommarskog <sommar@algonet.se> wrote in message news:Xns93EFA9C57954AYazorman@127.0.0.1... > MAB (fkdfjdierkjflafdafa@yahoo.com) writes: > > What I want is the sum of the amounts of the...
4
by: Toonman | last post by:
I'm trying to use a couple of variables in a stored procedure. Things work fine when I hard code the data into the variables and also work fine when I use the variable in the WHERE clause and hard...
2
by: Martin | last post by:
I am now working on SQL Server 2000 having had previous experience on a different database. Both of the OUTER JOIN syntaxes is different from what I am used to and I am finding it slightly...
8
by: Ike | last post by:
I am hoping someone can help me with the proper syntax for this. I have an attribute, called, say "name," such that: <set name="something">thename</set> However, the value for name, is...
177
by: C# Learner | last post by:
Why is C syntax so uneasy on the eye? In its day, was it _really_ designed by snobby programmers to scare away potential "n00bs"? If so, and after 50+ years of programming research, why are...
3
by: Ben | last post by:
I want to say: SELECT tableA.stuff,tableB.morestuff,tableC.stillmorestuff FROM tableA, LEFT OUTER JOIN tableB ON (AB match conditions) LEFT OUTER JOIN tableC ON (AC match conditions) WHERE etc...
21
by: Dmitry Anikin | last post by:
I mean, it's very convenient when default parameters can be in any position, like def a_func(x = 2, y = 1, z): ... (that defaults must go last is really a C++ quirk which is needed for overload...
0
by: butterflyTee | last post by:
USING:ORACLE 9i For each of the following tasks, determine (a) the SQL statement needed to perform the stated task using the traditional approach and (b) the SQL statement needed to perform the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.