所以我有这个SQLite字符串
SELECT
a.anchor as [From Anchor],
c.anchor as [To Anchor]
FROM table1 a
JOIN table2 b ON b.toAnchor = a.anchor
JOIN table3 c ON c.anchor = b.fromAnchor
执行它时没有错误,但它返回一个空表。所有3个表中都有数据,数据确实符合预期,但我什么都没得到。
表1
filename | farea | anchor
_________________________
file.doc N/A srs100
表2
type | filename | fromAnchor | toAnchor
_______________________________________
SRS N/A srs100 crs888
表3
filename | farea | anchor
_________________________
file.doc N/A crs888
我知道我可以使用表2,但我需要这样做才能找到来自和不匹配的区域。
如果我找不到这样做的方法那么我想找到一种方法,我可以组合2个表,所以它会这样。
表1
type | filename | fromAnchor | toAnchor
_______________________________________
SRS N/A crs100 srs888
表2
type | filename | fromAnchor | toAnchor
_______________________________________
CRS N/A srs888 srd999
结果
crs | srs | srd
_______________________________________
crs888 srs888 srd999
如果需要,我可以提供更多信息。现在我想知道sql调用是否正确。
答案 0 :(得分:2)
SELECT
a.anchor as [From Anchor],
c.anchor as [To Anchor]
FROM table1 a
JOIN table2 b ON b.fromAnchor = a.anchor
JOIN table3 c ON c.anchor = b.toAnchor
答案 1 :(得分:1)
试试这个
SELECT
fromAnchor,
toAnchor
from table2 a
join table1 b on a.fromAnchor =b.anchor
join table3 c on a.toAnchor =c.anchor
答案 2 :(得分:0)
原来数据库中的数据配置不正确。结果证明是有效的。
SELECT
TABLE1.toAnchor AS CRS,
TABLE1.fromAnchor AS SRS
FROM tbl_traces_srstraces
LEFT JOIN TABLE2 ON TABLE2.anchor = TABLE1.toAnchor
LEFT JOIN TABLE3 ON TABLE3.anchor = TABLE1.fromAnchor