|SQL - Structured Query Language|
SQL joins are used to retrieve data from two or more tables based on logical relationships between the tables. A typical join condition specifies a foreign key from one table and its associated key in the other table primary key. Logical operators are used to comparing values from the associated columns.
Note: For Demo, create DEPT and EMP Tables and then INSERT sample records.
Query Output Screen
Note: Tables cannot be joined directly on ntext, text, or image columns. However, tables can be joined indirectly on ntext, text, or image columns by using SUBSTRING.
For example, SELECT * FROM t1 JOIN t2 ON SUBSTRING(t1.textcolumn, 1, 20) = SUBSTRING(t2.textcolumn, 1, 20) performs a two-table inner join on the first 20 characters of each text column in tables t1 and t2.
In addition, another possibility for comparing ntext or text columns from two tables is to compare the lengths of the columns with a WHERE clause, for example: WHERE DATALENGTH(p1.pr_info) = DATALENGTH(p2.pr_info)
* * * * *