理解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中文網其他相關文章!