join on 后面的and 与where 的区别及用法

--- ==================== 先把数据导入数据库

CREATE TABLE `test_join_where_a`  (
  `aid` int(0) NOT NULL,
  `aname` varchar(255) ,
  `atimedate` datetime(0) ,
  `ascore` varchar(255)
);


INSERT INTO `test_join_where_a`(`aid`, `aname`, `atimedate`, `ascore`) VALUES (1, '张三', '2023-05-03 01:13:30', '80');
INSERT INTO `test_join_where_a`(`aid`, `aname`, `atimedate`, `ascore`) VALUES (2, '李四', '2023-06-22 01:15:09', '85');
INSERT INTO `test_join_where_a`(`aid`, `aname`, `atimedate`, `ascore`) VALUES (3, '王五', '2023-04-27 01:15:28', '78');
INSERT INTO `test_join_where_a`(`aid`, `aname`, `atimedate`, `ascore`) VALUES (4, '赵六', '2023-01-26 01:15:52', '68');


CREATE TABLE `test_join_where_b`  (
  `bid` int(0) NOT NULL,
  `bname` varchar(255) ,
  `btimedate` datetime(0) ,
  `bscore` varchar(255)
);


INSERT INTO `test_join_where_b`(`bid`, `bname`, `btimedate`, `bscore`) VALUES (1, '张三', '2023-05-03 01:13:30', '80');
INSERT INTO `test_join_where_b`(`bid`, `bname`, `btimedate`, `bscore`) VALUES (2, '李四', '2023-06-22 01:15:09', '85');
INSERT INTO `test_join_where_b`(`bid`, `bname`, `btimedate`, `bscore`) VALUES (3, '王五1', '2023-04-27 01:15:28', '78');
INSERT INTO `test_join_where_b`(`bid`, `bname`, `btimedate`, `bscore`) VALUES (4, '赵六', '2023-01-26 01:15:52', '68');

-- =================================

结论是:on 后面的and ,left join 与  right join 都是有效的。当把and换成where 后,left join 与  right join 功能失效了,这是sql 的执行的顺序造成的。

2、sql的执行顺序

   2.1、SQL的执行顺序_sql执行顺序优先级_洛禾符的博客-CSDN博客SQL的执行顺序_sql执行顺序优先级https://blog.csdn.net/luohefu1/article/details/122534905

       

你可能感兴趣的:(数据库sql,数据库,oracle)