Make unique number from 2 numbers There is any simple method to find a unique number from 2 different ones?
Currently I'm using $xy+x-y$ eg: 6•8+6-8 = 46 but I'm not able to test its reliability
X and Y range is 1~999,999,999
Info: the result must be unique, the method will be used in a SQL Query, keeping it simple/basic would be perfect
 A: It is easy to find a collision:
$$xy+x-y = (x-1)(y+1) + 1$$
so all we need is to find some number that can be written as a product in more than one way, and then declare the two factors to be $x-1$ or $y+1$, respectively.
For example $12=3\cdot 4=4\cdot 3$, so your function produces $13$ both for inputs $(4,3)$ and $(5,2)$.

What you want is a pairing function, for which many choices exist. A fairly practical one that works for nonnegative integers, as suggested by Wikipedia, is
$$ (x,y) \mapsto \frac{(x+y+1)(x+y)}2+x $$
For theoretical purposes it is sometimes convenient to use more "wasteful" functions such as 
$$ (x,y)\mapsto 2^x3^y $$
or
$$ (x,y) \mapsto 2^x(2y+1) $$
A: If $x,y\in[0,999999999]$, then you can use $f(x,y)=1000000000x+y$.
A: To see if your method works it is enough to see if
$$x\cdot y + x - y = x $$
or
$$x\cdot y + x - y = y $$
for any $x, y $.
Solving the first we get
$$ x\cdot y + x - y = x \iff x \cdot y - y = 0 \iff y(x-1) = 0 \iff x = 1 \vee y = 0$$
So your equation returns $x$ (regradless of $y $) if $x = 1$ or if $y = 0$ (regardless of $x $).
$$x\cdot y + x - y = y \iff x \cdot y + x = 2y \iff (y + 1)x = 2y \stackrel{y \not= -1}{\iff} x = \frac {2y}{y + 1}$$
Hence if $y \not= -1 \wedge x = \frac {2y}{y + 1}$ your method returns $y $.
Therefore your method is not 100% perfect. If you change it to
$$x\cdot y + x + y $$
By symmetry it would be enough to check that neither number is 0 or 1 to ensure it works.
A: Pick two primes $p$ and $q$ larger than $999,999,999$.  Solve the system $t \equiv X \pmod{p}$, $t\equiv Y \pmod{q}$ by the Chinese Remainder Theorem.  Then $t$ will be unique for each pair $(X,Y)$ modulo $pq>10^{18}.$
A: Equivalent Problem
To expand on the other answers posted, if you want to find a unique number for each $(x,y)$ pair of integers, you're really looking for a one-to-one function $f$, between $(x,y)$ and the set $\{0,1,2,\ldots\}$. In other words, an injection $f:\mathbb{N}^2\to\mathbb{N}$. Graphically, we can show $f$ in the diagram below as mapping between the grid of green points and the set of blue points, with the stipulation that no two blue points can have the same height.

It's quite simple to accommodate for the additional criterion that $f(x,y)=f(y,x)$ as we can choose the values of $f$ on one side of the plane $x=y$ and then allow $f(x,y)=f(y,x)$ on the other side of the plane.

Solutions

*

*One simple solution is to set all $(x,y)$ pairs into a grid with $x$ increasing along rows and $y$ increasing down columns. We then run a criss-crossing line through these points and take $f(x,y)$ as the position of $(x,y)$ along this line. This would look somewhat like the diagram below, which has fractions instead of number pairs.




*As Henning Makholm points out, this is actually one of a larger family of functions called Pairing Functions, which have the neat additional property that all the numbers in the set $\{0,1,2,\ldots\}$ can be mapped to. One such function is the one described in (1), the Cantor pairing function, $f(x,y)=\frac{(x+y)(x+y+1)}{2}+x$. This particular function works because $\frac{(x+y)(x+y+1)}2$ is constant along each diagonal in the grid above. So $f$ increases linearly along each diagonal, as in the diagram below.




*We can also use other functions such as $f(x,y)=(n+1)x+y$, if $x,y\leq n$ but this will only work if $x,y$ are strictly within these bounds. If you change the bounds later, this function might stop working, even though it seems neat at first.

