sqlite中的表别名,而不是mysql
我已经将完全相同的数据库表从MYSQL移动到了SQLITE。以下查询在MYSQL中工作sqlite中的表别名,而不是mysql,mysql,sqlite,Mysql,Sqlite,我已经将完全相同的数据库表从MYSQL移动到了SQLITE。以下查询在MYSQL中工作 select castkey, frname, lname, rolename from patrons, cast WHERE (patrons.personkey=cast.personkey) and cast.showkey=8 order by cast.roletype, sex desc 但是在SQLITE中,我得到了一个“靠近“.”的错误”语法错误。使用cast to c的表别名,查询工
select castkey, frname, lname, rolename from patrons, cast
WHERE (patrons.personkey=cast.personkey) and cast.showkey=8
order by cast.roletype, sex desc
但是在SQLITE中,我得到了一个“靠近“.”的错误”语法错误。使用cast to c的表别名,查询工作正常:
select castkey, frname, lname, rolename from patrons, cast as c
WHERE (patrons.personkey=c.personkey) and c.showkey=8
order by c.roletype, sex desc
Sqlite不喜欢查询的第一个版本的原因是什么?您使用的是旧的逗号连接语法。(1992年被取代) 试试这个
选择castkey、frname、lname、rolename
来自赞助人
加入对用户的强制转换。personkey=cast.personkey
其中cast.showkey=8
按演员顺序。角色类型,性别描述
您的别名情况应该会清除。您可以在列表中找到
CAST
。虽然SQLite允许使用大多数关键字作为标识符,但应避免使用它们,或者如果使用它们,应将它们括在反勾、方括号或双引号内。
这项工作:
select castkey, frname, lname, rolename
from patrons, cast
where (patrons.personkey=`cast`.personkey) and `cast`.showkey=8
order by `cast`.roletype, sex desc
但您也应该使用正确的联接语法:
select castkey, frname, lname, rolename
from patrons join cast
on (patrons.personkey=`cast`.personkey)
where `cast`.showkey=8
order by `cast`.roletype, sex desc
真正的错误是使用“cast”作为表名,而它也是一个关键字