日期:2014-05-16  浏览次数:20651 次

mysql中标准sql语句的用法

>> 设置级联更新或者删除:add constraint on delete cascade;

>> 链接查询:

语法格式:from TABLE1 join_type TABLE2 [on join_condition] [where query_condition]

join_condition:连接条件;query_condition:查询条件。

* 交叉查询(cross join):不带on字句,返回连接表中所有数据行的笛卡尔积,比如TABLE1有5行数据,TABLE2有7行数据,查询结果包含35(5 * 7)行数据。

交叉连接例子:select * from CUSTOMERS, ORDERS;

* 内连接(inner join):返回连接表中符合连接条件以及查询条件的数据行。

* 外连接,又分为左外连接(left outer join),右外连接(right outer join)。

左外连接:不仅返回连接表中符合连接条件以及查询条件的数据行,也返回左表中仅符合查询条件但不符合连接条件的数据行。

右外连接类似…

>> 子查询:

在select子句或者where子句中又嵌套select查询语句。

select * from CUSTOMERS c where 3 <= (select count(*) from ORDERS o where c.ID=o.CUSTOMERS_ID);

select * from ORDERS o where o.CUSTOMER_ID in (select ID from CUSTOMERS where NAME like ‘MIKE’);