473,231 Members | 2,894 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,231 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 3049
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: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.