Welcome Guest, Not a member yet? Register   Sign In
mysql query help
#1

[eluser]quasiperfect[/eluser]
hi

i have 3 tables and i need to get data from all 3 tables
for now i have the query

SELECT maxmind_locations.country,maxmind_locations.region,maxmind_locations.city FROM maxmind_cityblocks LEFT JOIN maxmind_locations ON maxmind_cityblocks.locId=maxmind_locations.locId WHERE 1449684273 BETWEEN maxmind_cityblocks.startIpNum AND maxmind_cityblocks.endIpNum


how can i modify the query to get maxmind_regions.name where maxmind_regions.code=maxmind_locations.region

can i do this in one query ?

the code for the tables is below

Code:
CREATE TABLE `maxmind_cityblocks` (
  `startIpNum` int(10) unsigned NOT NULL,
  `endIpNum` int(10) unsigned NOT NULL,
  `locId` int(10) unsigned NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8

CREATE TABLE `maxmind_locations` (
  `locId` int(10) unsigned NOT NULL,
  `country` char(2) NOT NULL,
  `region` char(2) DEFAULT NULL,
  `city` varchar(50) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8

CREATE TABLE `maxmind_regions` (
  `country` char(2) NOT NULL,
  `code` char(2) DEFAULT NULL,
  `name` varchar(50) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8
#2

[eluser]Cro_Crx[/eluser]
Hey mate

If you just change your select columns to have maxmind_regions.name instead of maxmind_locations.country,maxmind_locations.region,maxmind_locations.city.

Then just join the maxmind_regions and maxmind_locations tables together joining them on maxmind_regions.name and maxmind_regions.code=maxmind_locations.region.

I don't wanna give too much away, but yeah, have a go at that and let us know if you're still getting stuck.




Theme © iAndrew 2016 - Forum software by © MyBB