- 现有一张ldsysvar表里存有省+市+区 ,数据如图1
图1
2.效果图如图2
3.这是很常见的左连接查询语句,直接上sql,如下
SELECT
t3.nama1 as "一级地名(省)",
t3.name2 as "二级地名(市)",
t4.sysvarvalue as "三级地名(区)"
FROM
(
SELECT
t1.sysvar id1,
t1.sysvarvalue name1,
t1.sysvartype parent1,
t2.sysvar id2,
t2.sysvarvalue name2,
t2.sysvartype parent2
FROM
ldsysvar t1
LEFT JOIN ldsysvar t2 ON T1.sysvar = T2.sysvartype
WHERE
T1.sysvartype = '0'
) t3
LEFT JOIN ldsysvar t4 ON t3.id2 = T4.sysvartype
总结:
左连接:LEFT JOIN左边有的,右边没有的为null
右连接:RIGHT JOIN右边有的,左边没有的为null
内连接:显示左边右边共有的