14.05.2016 22:04, [email protected] [firebird-support] wrote:
> Above works. Merge below fails:
>
> merge into ZipCodeRef T1
> using ZipCodeDataBus T2
> on T2.ZipCode = T1.ZipCode
> when not matched then
> insert (ZipCode, Longitude, Latitude) values (T2.ZipCode, T2.Longitude,
> T2.Latitude);
By SQL standard MERGE must fail if several records from source matches
single record in
target. Add grouping to your source query like this:
merge into ZipCodeRef T1
using
(select ZipCode, MAX(Longitude) lo, MAX(Latitude) la
from ZipCodeDataBus
group by 1) as T2
on T2.ZipCode = T1.ZipCode
when not matched then
insert (ZipCode, Longitude, Latitude) values (T2.ZipCode, T2.Lo, T2.La);
--
WBR, SD.
------------------------------------
------------------------------------
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Visit http://www.firebirdsql.org and click the Documentation item
on the main (top) menu. Try FAQ and other links from the left-side menu there.
Also search the knowledgebases at http://www.ibphoenix.com/resources/documents/
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
------------------------------------
Yahoo Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/firebird-support/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/firebird-support/join
(Yahoo! ID required)
<*> To change settings via email:
[email protected]
[email protected]
<*> To unsubscribe from this group, send an email to:
[email protected]
<*> Your use of Yahoo Groups is subject to:
https://info.yahoo.com/legal/us/yahoo/utos/terms/