Formulas for counting pairs in a set I have a few questions regarding Cartesian products that will help me optimize a complicated SQL query I'm working on.
Suppose I have 52 playing cards, and I want to know how many combinations of pairs (first two cards) a dealer can draw at the beginning.  Obviously, this would be less than $52*52$ since the dealer cannot draw the same card twice.  So, to me it seems the answer is $(52*52) - 52$, since there's 52 "pairs" of the same card, in other words $52*51$.
However, I'd like to better understand the math behind this so I can apply it to any number of cards and any size sets:


*

*Given n cards, how many ordered sets of y cards can be created?
For example, if I had 100,000 cards, how many unique sets of 10 cards could I make?

*Given n cards, how many unordered sets of y cards can be created?
For example, if I had 100 cards, how many unique unordered sets of 3 could I make?
What's the mathematical formula that represents both these answers?  Thanks!

The concepts you are looking for are known as "permutations" and "combinations."


*

*If you have $n$ items, and you want to count how many ordered $r$-tuples you can make without repetitions, the answer is someimtes written $P^n_r$, and:
$$P^{n}_{r} = n(n-1)(n-2)\cdots (n-r+1).$$
This follows from the "multiplication rule": if event $A$ can occur in $p$ ways, and event $B$ can occur in $q$ ways, then the number of ways in which both events $A$ and $B$ can occur is $pq$.
Your answer of $52\times 51$ for ordered pairs of playing cards is correct if you care about which one is the first card and which one is the second. Another way to see this is that there are 52 possible ways in which the first card is dealt; and there are 51 ways for the second card to be dealt (as there are only 51 cards left).

*If you don't care about the order, then you have what are called "combinations" (without repeititons). The common symbol is
$$\binom{n}{k}$$
which is pronounces "$n$ choose $k$". The symbol represents the number of ways in which you can select $k$ elements from $n$ possibilities, without repetition. In other words, the number of ways to choose subsets with $k$ elements from a set with $n$ elements. The formula is
$$\binom{n}{k}=\frac{n!}{k!(n-k)!},\quad \text{if }0\leq k\leq n$$
where $n! = n\times (n-1)\times\cdots\times 2\times 1$.
To see this, note that there are $\frac{n!}{(n-k)!} = n(n-1)\cdots(n-k+1)$ ways of selecting $k$ items if you do care about the order. But since we don't care about the order, how many times did we pick each subset? For instance, a subset consisting of $1$, $2$, and $3$ is selected six times: once as 1-2-3, once as 1-3-2, once as 2-1-3, once as 2-3-1, once as 3-1-2, and once as 3-2-1. 
Well, there are $k$ items, and so there are $P^k_k$ ways of ordering them; this is exactly $k!$ ways. So we counted each $k$-subset $k!$ ways. So the final answer is $\frac{n!}{(n-k)!}$ divided by $k!$, giving the formula above,
$$\binom{n}{k}=\frac{n!}{k!(n-k)!}.$$ 
See also this previous question and answer for the general principles and formulas.
