<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Latest posts for the topic "Query for alternatename"]]></title>
		<link>http://forum.geonames.org/gforum/posts/list/4.page</link>
		<description><![CDATA[Latest messages posted in the topic "Query for alternatename"]]></description>
		<generator>JForum - http://www.jforum.net</generator>
			<item>
				<title>Query for alternatename</title>
				<description><![CDATA[ Hi whit this query  extract alla country from geoname table

<span class="genmed"><b>Code:</b></span><br>
		<div style="overflow: auto; width: 100%;">
		<pre>SELECT * FROM geoname where fcode = 'PCLI' and admin1=00</pre>
		</div>

now I wont extract alternate name from alternatename table for es language 
what query should I use?]]></description>
				<guid isPermaLink="true">http://forum.geonames.org/gforum/posts/list/2717.page#9784</guid>
				<link>http://forum.geonames.org/gforum/posts/list/2717.page#9784</link>
				<pubDate><![CDATA[Mon, 6 Jun 2011 06:21:35]]> GMT</pubDate>
				<author><![CDATA[ lillolollo]]></author>
			</item>
			<item>
				<title>Re:Query for alternatename</title>
				<description><![CDATA[ The clause 'admin1=00' is not required.
For the alternatenames you should join the two tables (geoname and alternatename table) on the geonameid. If you only are interested in Spanish you can filter for isolanguage='es'.

Best

Marc]]></description>
				<guid isPermaLink="true">http://forum.geonames.org/gforum/posts/list/2717.page#9788</guid>
				<link>http://forum.geonames.org/gforum/posts/list/2717.page#9788</link>
				<pubDate><![CDATA[Mon, 6 Jun 2011 06:23:32]]> GMT</pubDate>
				<author><![CDATA[ marc]]></author>
			</item>
			<item>
				<title>Re:Query for alternatename</title>
				<description><![CDATA[ Thanks marc but if I have this query for example

<span class="genmed"><b>Code:</b></span><br>
		<div style="overflow: auto; width: 100%;">
		<pre>SELECT *
FROM geoname, alternatename
WHERE geoname.fcode = 'PCLI'
AND geoname.geonameid = alternatename.geonameid
AND alternatename.isoLanguage = 'en'</pre>
		</div>

I have

Andorra 
Principality of Andorra

not only

Andorra

I dont want Principality of Andorra but only Andorra
]]></description>
				<guid isPermaLink="true">http://forum.geonames.org/gforum/posts/list/2717.page#9794</guid>
				<link>http://forum.geonames.org/gforum/posts/list/2717.page#9794</link>
				<pubDate><![CDATA[Tue, 7 Jun 2011 05:11:51]]> GMT</pubDate>
				<author><![CDATA[ lillolollo]]></author>
			</item>
			<item>
				<title>Re:Query for alternatename</title>
				<description><![CDATA[ There are a couple of flags to help you pick the name you prefer. In your case it is the 'isShortName' flag.

Best

Marc]]></description>
				<guid isPermaLink="true">http://forum.geonames.org/gforum/posts/list/2717.page#9796</guid>
				<link>http://forum.geonames.org/gforum/posts/list/2717.page#9796</link>
				<pubDate><![CDATA[Tue, 7 Jun 2011 06:45:24]]> GMT</pubDate>
				<author><![CDATA[ marc]]></author>
			</item>
			<item>
				<title>Re:Query for alternatename</title>
				<description><![CDATA[ Thanks again marc but if I use this query

<span class="genmed"><b>Code:</b></span><br>
		<div style="overflow: auto; width: 100%;">
		<pre>SELECT * FROM geoname where fcode = 'PCLI'</pre>
		</div>

have 192 country (I have deteted country whit no population)

If I use this

<span class="genmed"><b>Code:</b></span><br>
		<div style="overflow: auto; width: 100%;">
		<pre>SELECT *
FROM geoname, alternatename
WHERE geoname.fcode = 'PCLI'
AND geoname.geonameid = alternatename.geonameid
AND alternatename.isoLanguage = 'en' AND alternatename.isShortName=1</pre>
		</div>

have 117 country

if query is

<span class="genmed"><b>Code:</b></span><br>
		<div style="overflow: auto; width: 100%;">
		<pre>SELECT *
FROM geoname, alternatename
WHERE geoname.fcode = 'PCLI'
AND geoname.geonameid = alternatename.geonameid
AND alternatename.isoLanguage = '".$lang."' AND &#40;alternatename.isShortName=1 OR alternatename.isPreferredName=1&#41;</pre>
		</div>

have 131 country not 192]]></description>
				<guid isPermaLink="true">http://forum.geonames.org/gforum/posts/list/2717.page#9797</guid>
				<link>http://forum.geonames.org/gforum/posts/list/2717.page#9797</link>
				<pubDate><![CDATA[Tue, 7 Jun 2011 15:07:01]]> GMT</pubDate>
				<author><![CDATA[ lillolollo]]></author>
			</item>
			<item>
				<title>Re:Query for alternatename</title>
				<description><![CDATA[ of course. not every country has an entry for each language in the alternatenatename table, and not every country with an entry has the flags set, and others have both flags set.

You can either do a preprocessing when loading the geonames data or you have to use more complex queries with outer joins etc.

Best

Marc]]></description>
				<guid isPermaLink="true">http://forum.geonames.org/gforum/posts/list/2717.page#9800</guid>
				<link>http://forum.geonames.org/gforum/posts/list/2717.page#9800</link>
				<pubDate><![CDATA[Tue, 7 Jun 2011 22:39:21]]> GMT</pubDate>
				<author><![CDATA[ marc]]></author>
			</item>
			<item>
				<title>Re:Query for alternatename</title>
				<description><![CDATA[ Thanks marc can you provide an example query?]]></description>
				<guid isPermaLink="true">http://forum.geonames.org/gforum/posts/list/2717.page#9801</guid>
				<link>http://forum.geonames.org/gforum/posts/list/2717.page#9801</link>
				<pubDate><![CDATA[Tue, 7 Jun 2011 22:45:24]]> GMT</pubDate>
				<author><![CDATA[ lillolollo]]></author>
			</item>
			<item>
				<title>Re:Query for alternatename</title>
				<description><![CDATA[ I would do it as a preprocessing on the application level otherwise if you want to do it on the db you can use window functions if your database supports it. Sort the window by your favorite criteria and get the best one with the first_value function.

For postgres it would look like this:

<span class="genmed"><b>Code:</b></span><br>
		<div style="overflow: auto; width: 100%;">
		<pre>
select distinct countrycode,first_value&#40;name&#41; over &#40;partition by countrycode&#41; as bestname from &#40;select countrycode,case when alternatename.name is not null then alternatename.name else geoname.name end from geoname left outer join alternatename on alternatename.geonameid=geoname.geonameid and alternatename.namelocale='en' where featureclass ='A' and featurecode like 'PCL%' order by countrycode,isShortName desc nulls last,isofficialname desc nulls last&#41;t order by countrycode;
</pre>
		</div>


Marc]]></description>
				<guid isPermaLink="true">http://forum.geonames.org/gforum/posts/list/2717.page#9923</guid>
				<link>http://forum.geonames.org/gforum/posts/list/2717.page#9923</link>
				<pubDate><![CDATA[Sun, 12 Jun 2011 07:18:11]]> GMT</pubDate>
				<author><![CDATA[ marc]]></author>
			</item>
			<item>
				<title>Re:Query for alternatename</title>
				<description><![CDATA[ thanks marc very useful]]></description>
				<guid isPermaLink="true">http://forum.geonames.org/gforum/posts/list/2717.page#9937</guid>
				<link>http://forum.geonames.org/gforum/posts/list/2717.page#9937</link>
				<pubDate><![CDATA[Thu, 16 Jun 2011 04:31:29]]> GMT</pubDate>
				<author><![CDATA[ lillolollo]]></author>
			</item>
	</channel>
</rss>