join on 与 where 条件的执行先后顺序:

  join on 条件先执行,where条件后执行;join on的条件在连接表时过滤,而where则是在生成中间表后对临时表过滤

 

left join、right join、full join、inner join区别:

  left join:以左表为基准,根据on条件过滤连接生成临时表,on后面的过滤条件对左表无效

  right join:以右表为基准,根据on条件过滤连接生成临时表,on后面的过滤条件对右表无效

  full join:以左表为基准,根据on条件过滤连接生成临时表,on后面的过滤条件对左右表无效

  inner join:等值连接,根据过滤条件生成临时表。用inner join 后面的条件 可以用 where实现

  

  where:对生成的临时表进行过滤,inner join能完成的功能用where条件都可以完成,但反之则不是啦。

 

建表语句:

 1 CREATE TABLE `t_salecategory_product_relation` (
 2   `relation_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键列',
 3   `product_id` int(11) NOT NULL COMMENT '商品ID,外键',
 4   `product_code` varchar(32) NOT NULL COMMENT '商品编码',
 5   `category_id` bigint(20) NOT NULL COMMENT '运营分类ID,外键,对应表t_sale_category中的主键列',
 6   `category_code` varchar(64) NOT NULL COMMENT '运营分类编号',
 7   `order_value` int(11) DEFAULT NULL COMMENT '排序值,在搜索时使用,按降序排',
 8   `mount_type` smallint(6) NOT NULL COMMENT '挂载类型:\r\n                1:自动挂载;\r\n                2:手动挂载\r\n            ',
 9   `opt_type` smallint(6) DEFAULT NULL COMMENT '操作类型: 1 更新  2 删除 ,默认为1',
10   `mount_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '挂载时间',
11   `mount_user` varchar(64) DEFAULT NULL COMMENT '挂载人',
12   `last_update_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '最后修改时间',
13   `last_update_user` varchar(64) DEFAULT NULL COMMENT '最后修改人',
14   PRIMARY KEY (`relation_id`),
15   UNIQUE KEY `IDX_productcode_salecode` (`product_code`,`category_code`),
16   KEY `FK_product_saleCategory` (`category_id`),
17   KEY `FK_salCatProduct_prdInfo` (`product_id`),
18   CONSTRAINT `FK_salCatProduct_prdInfo` FOREIGN KEY (`product_id`) REFERENCES `t_product` (`product_id`) ON DELETE CASCADE,
19   CONSTRAINT `FK_FK_saleCategory_saleCategoryProductRelation` FOREIGN KEY (`category_id`) REFERENCES `t_sale_category` (`category_id`)
20 ) ENGINE=InnoDB AUTO_INCREMENT=106 DEFAULT CHARSET=utf8 COMMENT='运营分类和商品挂载关系表';
View Code

相关文章:

  • 2021-08-19
  • 2021-11-28
  • 2021-05-02
  • 2021-12-26
  • 2021-05-26
  • 2021-07-13
猜你喜欢
  • 2021-09-25
  • 2022-12-23
  • 2021-06-19
  • 2021-09-25
  • 2021-08-29
  • 2021-03-31
相关资源
相似解决方案