将具有右外连接的访问查询转换为 sqlite 查询
Posted
技术标签:
【中文标题】将具有右外连接的访问查询转换为 sqlite 查询【英文标题】:Convert access query with right outer join to sqlite query 【发布时间】:2012-08-24 10:43:06 【问题描述】:SELECT t13_Literature_Material_Codes.Databank, t13_Literature_Material_Codes.BASE_NUMB, t13_Literature_Material_Codes.BASE_SYMB, t13_Literature_Material_Codes.BASE_CHAR, t13_Literature_Material_Codes.BASE_MOLW, CorrosionRatesInfo.RatesValidFlag
FROM CorrosionRatesInfo RIGHT JOIN t13_Literature_Material_Codes ON CorrosionRatesInfo.BASE_NUMB=t13_Literature_Material_Codes.BASE_NUMB;
如何在 sqlite 中进行此查询?我看到人们使用左外连接。请提供使用类似结构的解决方案,然后我的 c++ 程序可以使用简单的解析器过程修改查询字符串。
【问题讨论】:
【参考方案1】:在 Sqlite 中执行此查询:
SELECT t13_Literature_Material_Codes.Databank, t13_Literature_Material_Codes.BASE_NUMB,
t13_Literature_Material_Codes.BASE_SYMB, t13_Literature_Material_Codes.BASE_CHAR,
t13_Literature_Material_Codes.BASE_MOLW, CorrosionRatesInfo.RatesValidFlag FROM
CorrosionRatesInfo RIGHT OUTER JOIN t13_Literature_Material_Codes ON
CorrosionRatesInfo.BASE_NUMB=t13_Literature_Material_Codes.BASE_NUMB;
只需添加“RIGHT OUTER JOIN”即可。
【讨论】:
我尝试了“右外连接”,但出现错误:当前不支持右外连接和全外连接 “SELECT t13_Literature_Material_Codes.Databank,t13_Literature_Material_Codes.BASE_NUMB,t13_Literature_Material_Codes.BASE_SYMB,t13_Literature_Material_Codes.BASE_CHAR,t13_Literature_Material_Codes.BASE_MOLW,CorrosionRatesInfo.RatesValidFlag FROM t13_Literature_Material_Codes LEFT JOIN CorrosionRatesInfo上CorrosionRatesInfo.BASE_NUMB = t13_Literature_Material_Codes.BASE_NUMB” 成功了!我交换了表名并将“右连接”更改为“左连接”【参考方案2】:用户 UNION 来解决这个问题
举例
SELECT employee.*, department.*
FROM employee
LEFT JOIN department
ON employee.DepartmentID = department.DepartmentID
UNION ALL
SELECT employee.*, department.*
FROM department
LEFT JOIN employee
ON employee.DepartmentID = department.DepartmentID
WHERE employee.DepartmentID IS NULL
是的,see the example on Wikipedia.
【讨论】:
以上是关于将具有右外连接的访问查询转换为 sqlite 查询的主要内容,如果未能解决你的问题,请参考以下文章