Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将查询从mysql转换为sqlite3_Mysql_Sql_Sqlite - Fatal编程技术网

将查询从mysql转换为sqlite3

将查询从mysql转换为sqlite3,mysql,sql,sqlite,Mysql,Sql,Sqlite,我有一个非常简单的MySQL查询 select clients.id as selected_id,(select clients.id from clients where clients.id=selected_id) from clients where clients.id=20 当我在MySQL上运行它时,它运行得很好。但是在Sqlite3上,同样的查询抛出 错误:没有这样的列:已选择\u id 我试着用谷歌搜索,但大多数解决方案都是w.r.t.连接。在这里,我需要在select

我有一个非常简单的MySQL查询

select clients.id as selected_id,(select clients.id 
from clients where clients.id=selected_id) 
from clients where clients.id=20
当我在MySQL上运行它时,它运行得很好。但是在Sqlite3上,同样的查询抛出

错误:没有这样的列:已选择\u id


我试着用谷歌搜索,但大多数解决方案都是w.r.t.连接。在这里,我需要在select部分中使用它。

SQLite符合SQL标准,即select子句中的别名仅用于输出列,但在子句本身中不可用

使用这样的相关子查询的正确方法是重命名其中一个表:

SELECT id AS selected_id,
       (SELECT id 
        FROM clients AS c2       -- !
        where c2.id = clients.id
       ) AS the_other_id
FROM clients
WHERE id = 20

使用联接有什么问题?不能将id别名为selected_id并在类似的子查询中使用它。您需要为这些表添加别名,并根据它们的id连接它们。尽管如此,我还是不明白你询问的要点。您想要实现什么?已经构建了一个大型查询来运行MySQL。现在,我们正在移植相同的代码来运行sqlite,我们需要确保进行最小的更改。我明白了。很好。谢谢