select
select 2*7 as res; 【as res: 把res当作字段(别名) as: 用作;别名】
mysql> select 'qnmd'
-> ;
+------+
| qnmd |
+------+
| qnmd |
+------+
1 row in set (0.00 sec)
mysql> select 2*7;
+-----+
| 2*7 |
+-----+
| 14 |
+-----+
1 row in set (0.01 sec)
mysql> select 'go fuck' as qnmd;
+---------+
| qnmd |
+---------+
| go fuck |
+---------+
1 row in set (0.00 sec)
mysql> select 2*7 as res;
+-----+
| res |
+-----+
| 14 |
+-----+
1 row in set (0.00 sec)
from
· select * from /表名/;
· select * from /表名/,/表名/...;多个表一起查,会返回笛卡尔积
mysql> select * from t1;
+------+----------+
| id | name |
+------+----------+
| 1 | noooryes |
| 2 | Tom |
+------+----------+
2 rows in set (0.00 sec)
mysql> select * from t2;
+--------+--------+
| score1 | score2 |
+--------+--------+
| 99 | 11 |
| 99 | 61 |
+--------+--------+
2 rows in set (0.00 sec)
mysql> select * from t1, t2;
+------+----------+--------+--------+
| id | name | score1 | score2 |
+------+----------+--------+--------+
| 1 | noooryes | 99 | 11 |
| 2 | Tom | 99 | 11 |
| 1 | noooryes | 99 | 61 |
| 2 | Tom | 99 | 61 |
+------+----------+--------+--------+
4 rows in set (0.00 sec)
dual
eg:select 2*7 as res from dual;【from dual可以不写】
dual是一个虚拟表
mysql> select 2*7 as res from dual;
+-----+
| res |
+-----+
| 14 |
+-----+
1 row in set (0.00 sec)
mysql> select 2*7 as res;
+-----+
| res |
+-----+
| 14 |
+-----+
1 row in set (0.00 sec)
where
作用是条件筛选,一条一条地查
mysql> select * from t1;
+------+----------+
| id | name |
+------+----------+
| 1 | noooryes |
| 2 | Tom |
| 3 | Tom |
| 4 | Tom |
+------+----------+
4 rows in set (0.01 sec)
mysql> select * from t1 where name='Tom' and id=3;
+------+------+
| id | name |
+------+------+
| 3 | Tom |
+------+------+
1 row in set (0.01 sec)
in(替代=),not in
in: 限定查找范围
mysql> select * from t1 where name in ('Tom');
+------+------+
| id | name |
+------+------+
| 2 | Tom |
| 3 | Tom |
| 4 | Tom |
+------+------+
3 rows in set (0.01 sec)