All pastes #970600 Raw Edit

EricB

public text v1 · immutable
·published 2008-04-04 04:04 UTC
rendered paste body
mysql> create table t (t int);
Query OK, 0 rows affected (0.00 sec)

mysql> create table u (u int);
Query OK, 0 rows affected (0.01 sec)

mysql> select @a:=0; 
+-------+
| @a:=0 |
+-------+
|     0 | 
+-------+
1 row in set (0.06 sec)

mysql> insert into t set t=@a:=@a+1;
Query OK, 1 row affected (0.03 sec)

mysql> insert into t set t=@a:=@a+1;
Query OK, 1 row affected (0.00 sec)

mysql> insert into t set t=@a:=@a+1;
Query OK, 1 row affected (0.00 sec)

mysql> insert into t set t=@a:=@a+1;
Query OK, 1 row affected (0.00 sec)

mysql> select @a:=0;
+-------+
| @a:=0 |
+-------+
|     0 | 
+-------+
1 row in set (0.00 sec)

mysql> insert into u set u=@a:=@a+1;
Query OK, 1 row affected (0.00 sec)

mysql> insert into u set u=@a:=@a+1;
Query OK, 1 row affected (0.00 sec)

mysql> insert into u set u=@a:=@a+1;
Query OK, 1 row affected (0.00 sec)

mysql> select @a:=@a+1;;
+----------+
| @a:=@a+1 |
+----------+
|        4 | 
+----------+
1 row in set (0.00 sec)

ERROR: 
No query specified

mysql> insert into u set u=@a:=@a+1;
Query OK, 1 row affected (0.00 sec)

mysql> select * from t
    -> ;
+------+
| t    |
+------+
|    1 | 
|    2 | 
|    3 | 
|    4 | 
+------+
4 rows in set (0.00 sec)

mysql> select * from u;
+------+
| u    |
+------+
|    1 | 
|    2 | 
|    3 | 
|    5 | 
+------+
4 rows in set (0.00 sec)

mysql> select * from t left join u on t.t = u.t;
ERROR 1054 (42S22): Unknown column 'u.t' in 'on clause'
mysql> select * from t left join u on t.t = u.u;
+------+------+
| t    | u    |
+------+------+
|    1 |    1 | 
|    2 |    2 | 
|    3 |    3 | 
|    4 | NULL | 
+------+------+
4 rows in set (0.04 sec)

mysql> select * from t left join u on t.t = u.u group by t.t;
+------+------+
| t    | u    |
+------+------+
|    1 |    1 | 
|    2 |    2 | 
|    3 |    3 | 
|    4 | NULL | 
+------+------+
4 rows in set (0.02 sec)

mysql> select t,count(u) from t left join u on t.t = u.u group by t.t;
+------+----------+
| t    | count(u) |
+------+----------+
|    1 |        1 | 
|    2 |        1 | 
|    3 |        1 | 
|    4 |        0 | 
+------+----------+
4 rows in set (0.00 sec)