Jump to content

Recommended Posts

I’m new to php so bare with me  ;)

 

Here is my problem:

I have two tables in the same database –

 

Table1

Ip city

10.0.10 NY

10.0.20 LA

10.0.30 CH

 

Table2

Ip info1 info2 info3 info4

10.0.10.1 123 123 123 123

10.0.10.2 123 123 123 123

10.0.10.3 123 123 123 123

10.0.10.4 123 123 123 123

10.0.20.1 123 123 123 123

10.0.20.2 123 123 123 123

10.0.20.3 123 123 123 123

10.0.20.4 123 123 123 123

10.0.30.1 123 123 123 123

10.0.30.2 123 123 123 123

10.0.30.3 123 123 123 123

10.0.30.4 123 123 123 123

 

 

I was trying to query something like this:

SELECT * FROM db. Table1, db. Table2

WHERE db.Table1.ip LIKE db. Table2.Ip.%

 

 

Then the output looks like this:

 

NY

10.0.10.1 123 123 123 123

10.0.10.2 123 123 123 123

10.0.10.3 123 123 123 123

10.0.10.4 123 123 123 123

 

LA

10.0.20.1 123 123 123 123

10.0.20.2 123 123 123 123

10.0.20.3 123 123 123 123

10.0.20.4 123 123 123 123

 

CH

10.0.30.1 123 123 123 123

10.0.30.2 123 123 123 123

10.0.30.3 123 123 123 123

10.0.30.4 123 123 123 123

 

I hope this makes sense :)

Also any help would be greatly appreciated  ;D ;D

Link to comment
https://forums.phpfreaks.com/topic/152001-php-and-two-mysql-statement/
Share on other sites

First I would like to say sorry about not reading the Sticky about posting, I posted under PHP.

 

Sounds like you need UNION.

 

Union is great but I only can select the same amount of rows.

SELECT ipAddress FROM sencore.1066
UNION
SELECT IPAddress FROM sencore.66ipAddress WHERE sencore.66ipAddress.IPAddress LIKE "sencore.1066.ipAddress.%"

 

sencore.1066 have about 30 fields :(

sencore.66ipAddress only have 2

 

Any other suggestions?

 

CREATE TABLE  `sencore`.`1066` (
  `id` int(11) NOT NULL auto_increment,
  `IPAddress` varchar(100) default NULL,
  `displaymode` varchar(100) default NULL,
  `analogoutput` varchar(100) default NULL,
  `formatmode` varchar(100) default NULL,
  `videoformat` varchar(100) default NULL,
  `failuremode` varchar(100) default NULL,
  `line4` varchar(100) default NULL,
  `line5` varchar(100) default NULL,
  `line6` varchar(100) default NULL,
  `line7` varchar(100) default NULL,
  `line8` varchar(100) default NULL,
  `line9` varchar(100) default NULL,
  `line10` varchar(100) default NULL,
  `line11` varchar(100) default NULL,
  `line12` varchar(100) default NULL,
  `line13` varchar(100) default NULL,
  `line14` varchar(100) default NULL,
  `line15` varchar(100) default NULL,
  `pSNMPserver` varchar(100) default NULL,
  `bSNMPserver` varchar(100) default NULL,
  `read` varchar(100) default NULL,
  `write` varchar(100) default NULL,
  `pid` varchar(100) default NULL,
  `format1` varchar(100) default NULL,
  `format2` varchar(100) default NULL,
  `format3` varchar(100) default NULL,
  `format4` varchar(100) default NULL,
  `chromaformat` varchar(100) default NULL,
  `level1` varchar(100) default NULL,
  `level2` varchar(100) default NULL,
  `asitype` varchar(100) default NULL,
  `mer` varchar(100) default NULL,
  `channel` varchar(100) default NULL,
  `lowlevel` varchar(100) default NULL,
  `lowmer` varchar(100) default NULL,
  `modulationmode` varchar(100) default NULL,
  `channelplan` varchar(100) default NULL,
  `CurrentInput` varchar(100) default NULL,
  `BackupInput` varchar(100) default NULL,
  `ServiceSelectionMode` varchar(100) default NULL,
  `ServiceNumber` varchar(100) default NULL,
  `Notes` varchar(100) default NULL,
  `alias` varchar(100) default NULL,
  `sencore` varchar(100) default NULL,
  `unitversion` varchar(100) default NULL,
  `decoderVersion` varchar(100) default NULL,
  `tssid` varchar(100) default NULL,
  `stationname` varchar(100) default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=8503 DEFAULT CHARSET=latin1;

 

CREATE TABLE  `sencore`.`66ipAddress` (
  `ipAddress` varchar(45) default NULL,
  `cityCode` varchar(45) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

 

SELECT ipAddress FROM sencore.1066
UNION
SELECT IPAddress FROM sencore.66ipAddress WHERE sencore.66ipAddress.IPAddress LIKE "sencore.1066.ipAddress.%"

 

Trying to do a Union with a LIKE statement to see how that works :)

I'm really a newbie at all of this :)

 

Thanks again for all your help fenway ;D ;D ;D ;D

First off, many thanks for reply to my questions fenway

 

What I would like my out to look like:

cityCode
    IPAddress
  Notes
  alias
  sencore
  unitversion
  decoderVersion
  tssid
  stationname

cityCode
    IPAddress
  Notes
  alias
  sencore
  unitversion
  decoderVersion
  tssid
  stationname

 

Each with a new cityCode :)

I hope that make sense

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.