我有4個表來填充表3返回的數據如何聯接表
1. the first table(d_cities) for cities // related with the next table by country_id
CityId |CountryID |RegionID |City |Latitude|Longitude
2. the second table(d_country) for countries
CountryId|Country
3. the third table(ip2location_db11) for ip
ip_from|ip_to |country_code|country_name| city_name
4 the fourth table (ip_relation) would be like this
CountryID |CityId|ip_from |ip_to
我創建的第四個表來收集來自三個表自定義數據,並把它放在一個表.. 這將有一直秉乘:
通過ID加入(d_country,d_cities), 然後用IP表比較這名如果匹配 將取回的ID爲這些名稱& IPS匹配,並把它的第四個表 ..所以我寫這樣的代碼,需要支持修改此代碼
INSERT ip_relations (CountryID, CityId,ip_from,ip_to)
SELECT *
FROM d_cities
INNER JOIN d_country ON d_cities.CountryID = d_country.CountryId
INNER JOIN ip2location_db11 ON ip2location_db11.country_name = d_country.Country
AND ip2location_db11.city_name = d_cities.City
///這條SQL語句不行
我想通過選擇三個表來更新第四張表 – user1080247
好的,我已經編輯過它 –
#1064 - 你的SQL語法錯誤;檢查與您的MySQL服務器版本對應的手冊,以便在第7行的'FROM d_country LEFT JOIN d_cities ON d_country.CountryId = d_cities.CountryID'附近使用正確的語法。 – user1080247