JOIN中的结果为空

时间:2016-02-21 03:38:49

标签: mysql left-join

我在mysql查询中遇到以下问题:

SELECT t2.ordering, t1.family, t1.type, t1.game 
FROM (SELECT 
    landbased_results.game, 
    landbased_results.type, 
    landbased_results.family 
FROM landbased_results 
Group by family, type,game) t1 
LEFT JOIN
(SELECT family, ordering FROM family_order) t2 
ON t1.family = t2.family 
ORDER BY t2.ordering, t1.family, t1.type, t1.game ASC

给我以下结果:

+----------+--------------+-------------+---------+
| ordering | family       | type        | game    |
+----------+--------------+-------------+---------+
| NULL     | Punto  Banco | Punto Banco | PB 1    |
| NULL     | Punto  Banco | Punto Banco | PB 2    |
| NULL     | Punto  Banco | Punto Banco | PB 3    |
| 1        | Roulette     | Canasta     | CA 1    |
| 1        | Roulette     | Canasta     | CA 2    |
| 1        | Roulette     | Canasta     | CA 3    |
| 1        | Roulette     | Canasta     | CA 4    |
| 2        | Blackjack    | Rummy       | RUM 1   |
| 2        | Blackjack    | Rummy       | RUM 2   |
| 2        | Blackjack    | Rummy       | RUM 3   |
| 2        | Blackjack    | Rummy       | RUM 4   |
| 2        | Blackjack    | Rummy       | RUM 5   |
| 4        | Multi-games  | Multi-games | MULTI 1 |
| 4        | Multi-games  | Multi-games | MULTI 2 |
| 4        | Multi-games  | Multi-games | MULTI 3 |
| 5        | Pokers       | Pai Go      | PG 1    |
| 5        | Pokers       | Pai Go      | PG 2    |
| 5        | Pokers       | Poker       | PK 1    |
| 5        | Pokers       | Texas       | TEXAS 1 |
| 5        | Pokers       | Texas       | TEXAS 2 |
| 5        | Pokers       | Texas       | TEXAS 3 |
| 5        | Pokers       | Tute        | TUTE 1  |
| 7        | Craps        | Craps       | CR 1    |
| 8        | Slots        | Slots       | Slots   |
+----------+--------------+-------------+---------+

为什么我在"订购"?中得到一个NULL结果?该表有一个明确的订购密钥:

+----+-------------+----------+
| id | family      | ordering |
+----+-------------+----------+
| 1  | Blackjack   | 2        |
| 2  | Craps       | 7        |
| 3  | Multi-games | 4        |
| 4  | Pokers      | 5        |
| 5  | Punto Banco | 3        |
| 6  | Roulette    | 1        |
| 7  | Slots       | 8        |
| 8  | Super Pic   | 6        |
+----+-------------+----------+

我做错了什么?

0 个答案:

没有答案