- 一对多
–注意事项,使用左外连接而非内连接
SELECT c., o.
from t_customer c left outer join t_order o on c.customer_id = o.cid
where c.customer_id = 4;
SELECT c., o.
from t_customer c inner join t_order o on c.customer_id = o.cid
where c.customer_id = 4;
-
多对一
<!-- 多对一的关系 --> <!-- property: 指的是属性的值, javaType:指的是属性的类型--> <association property="customer" javaType="Customer"> <id column="customer_id" property="customerId"/> <result column="customer_name" property="customerName"/> </association>
为什么多对一可以使用内连接???
select o., c.
from t_order o inner join t_customer c on o.cid = c.customer_id
where o.order_id = #{orderId,jdbcType=INTEGER} -
多对多
SELECT n.news_id, n.title, c.category_id, c.category_name
FROM t_news n left outer join t_news_category nc on n.news_id = nc.nid left outer join t_category c on nc.cid = c.category_id
where n.news_id = #{newsId,jdbcType=INTEGER}
-
新闻添加或删除类别
-
新闻删除
-
作业
多对多关系删除