Mysql update alle Zeilen basiert auf der Auswahl aus einer anderen Tabelle

Ich habe zwei Tabellen;

mysql> describe ipinfo.ip_group_country;
+--------------+-------------+------+-----+---------+-------+
| Field        | Type        | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| ip_start     | bigint(20)  | NO   | PRI | NULL    |       |
| ip_cidr      | varchar(20) | NO   |     | NULL    |       |
| country_code | varchar(2)  | NO   | MUL | NULL    |       |
| country_name | varchar(64) | NO   |     | NULL    |       |
+--------------+-------------+------+-----+---------+-------+

mysql> describe logs.logs;
+----------------------+------------+------+-----+---------------------+----------------+
| Field                | Type       | Null | Key | Default             | Extra          |
+----------------------+------------+------+-----+---------------------+----------------+
| id                   | int(11)    | NO   | PRI | NULL                | auto_increment |
| ts                   | timestamp  | NO   |     | CURRENT_TIMESTAMP   |                |
| REMOTE_ADDR          | tinytext   | NO   |     | NULL                |                |
| COUNTRY_CODE         | char(2)    | NO   |     | NULL                |                |
+----------------------+------------+------+-----+---------------------+----------------+

Kann ich Land auswählen-code mit ip-Adresse aus der ersten Tabelle:

mysql> SELECT country_code FROM ipinfo.`ip_group_country` where `ip_start` <= INET_ATON('74.125.45.100') order by ip_start desc limit 1;
+--------------+
| country_code |
+--------------+
| US           |
+--------------+

In Protokollen.Protokolle habe ich alle die REMOTE_ADDR (ip-Adresse) gesetzt, aber alle COUNTRY_CODE Einträge sind leer. Nun, ich möchte zum Auffüllen COUNTRY_CODE entsprechend mit der ipinfo Tabelle. Wie kann ich dies tun?

Dank!

InformationsquelleAutor anon | 2011-01-27
Schreibe einen Kommentar