理解 SQL 连接中“=*”的含义
在检查 Microsoft SQL Server 代码时,可能会遇到不熟悉的连接约定:“=*。”此语法在 SQL Server 2005 之前就有历史根源,具有特定的含义,并且不是 ANSI JOIN。
“=*”Join 的语法
“=*”连接语法采用以下形式形式:
WHERE table1.yr =* table2.yr -1
定义
“=*”连接是使用以下逻辑的外连接:
示例
考虑以下表:
table1: | yr | data | | ----------- | -------- | | 2022 | x | | 2023 | y | table2: | yr | value | | ----------- | --------- | | 2021 | a | | 2022 | b |
以下查询使用“=*”连接进行组合这些表:
SELECT * FROM table1 WHERE table1.yr =* table2.yr -1;
此查询将产生以下结果结果:
yr | data | value |
---|---|---|
2022 | x | b |
2023 | y | NULL |
**Note:** The "-1" in the query subtracts one year from the "yr" column of table2, resulting in a match for "2022" from table1. **Historical Significance and ANSI Joins** The "=*" join syntax was prevalent in older versions of TSQL. However, since SQL Server 2005, ANSI JOIN syntax is preferred. The ANSI JOIN syntax uses keywords such as "INNER JOIN", "LEFT JOIN", and "RIGHT JOIN" to specify the type of join.
以上是SQL 连接中的'=*”语法意味着什么?的详细内容。更多信息请关注PHP中文网其他相关文章!