Mysql 查询语句大全 \1.两表之间的查询,例如:查询员工表中部门号与部门表中部门号相等 select * from tb_emp ,tb_dept where tb_emp.deptno=tb_dept.deptno; (这是同时显示两张表中相等的depton 所有字段)(tb_emp ,tb_dept 这都是表名) 2.select tb_e.deptno from tb_e, tb_d where tb_e.deptno=tb_d.deptno; (这是只显示员工表中的tb_e.deptno,并且条件是员工表中部门号与部门表中部门号相等) 3.给字段取别名 select product_price*12 totsl_product_price from productinfo; 等价select product_price*12 from productinfo; 也可以这样写 select product_price*12 " totsl product_price" from productinfo; 有特殊的字符时用双引号的方法,(特殊字符是:中文,日文,分号等)(totsl product_price是 product_price*12) ****** 0 和空 还有空格不是一个概念 例如: select * from emp where description is null; select * from emp where description =0; select * from emp where description ='空格'; 查询的结果都市不一样的。 distinct 关键字可以查询结果中清除重复的行,他的作用范围是后面的所有字段的组合; 例如: select distinct deptno ,deptname from emp where deptno=23; totsl_product_price 是product_price 的别名; select ename, sal*12 as '年薪'from emp; 别名的作用是 让查询出来的结果可以让别人(外行)看了一目了然的作用 上面是针对产品价格计算出总金额,价格*12,也就是对字段值进行加减乘除, *****任何含有空值的表达式计算后的值都是空值。( 空值+20=空值,等等) 不等值查询(mysql 两者都支持) select * from productinfo where product_id!=33; oracl 的不等值查询 select * from productinfo where product_id<>'33'; 小于查询 select * from productinfo where product_id<'33'; 大于查询 select * from productinfo where product_id>'33'; 等于查询 select * from productinfo where product_id='33'; 在一定值范围内查询 例如 1000--5000 的查询 select ename, sal as '月薪'from emp where sal>=1000 and sal<=5000; 在两个值之间的查询 between...... and (包含最小值和最大值) select ename, sal as '月薪'from emp...