查询语法
select 列 1, 列 2,... 列 n
from 表名
where 条件
- 1. 查询表的多有行所有列
- select * from user;
- 开发中很少这样写 , 因为表中会有成千上万的数据 , 这样查询会增加数据库负担
- 2. 查询一行
- select * from user where id=12;
- 3. 查询多行
- select * from user where id>=12;
- 4. 查询某几行的某几列 ,* 代表所有列
- select name,age from user where uid>=12;
- select name from user where uid=12;
- 5. 列是变量
- 每一行 , 变量值在变
- 从上到下 , 遍历行 ,where 是表达式 , 当 值为真 , 则取出该行
- select * from user where 1; // 取出所有行
- select * from user where 0; // 一行都取不出来
- 6. 变量可以计算
- select name,age+1 from user where 1;
提示:
大胆的把列看成变量 , 参与运算 , 甚至调用函数来处理 ,如:substring(),concat()等,
- select goods_id,substring(goods_name,4) from goods where goods_name like '诺基亚%';
- select goods_id,concat('HTC',substring(goods_name,4)) from goods where goods_name like '诺基亚%';
- update goods set goods_name=concat('HTC',substring(goods_name,4)) where goods_name like '诺基亚%';
注意:后面的教程会用上goods等相关表,goods是ecshop默认的ecs_goods表修改而来的,因为这个表比较全面,可以用来做查询测试;如果没有相关表的;
请点击百度网盘链接下载: http://pan.baidu.com/s/1geAomUf 密码: zad4