下面是我的表结构。
create table "APP".REGISTRATION
(
"id" INT not null primary key GENERATED ALWAYS AS IDENTITY(START WITH 1,INCREMENT BY 1),
"firstname" VARCHAR(50),
"lastname" VARCHAR(50),
"username" VARCHAR(50),
"password" VARCHAR(50),
"email" VARCHAR(50)
);
我插入了一行:
firstname=susheel lastname=singh username=susheel61 password=password email=test@gmail.com
现在我尝试查询
select * from REGISTRATION where USERNAME='susheel61';
我收到错误消息:
> Error code 0, SQL state 42X04: Column 'USERNAME' is either not in any
> table in the FROM list or appears within a join specification and is
> outside the scope of the join specification or appears in a HAVING
> clause and is not in the GROUP BY list. If this is a CREATE or ALTER
> TABLE statement then 'USERNAME' is not a column in the target table.
答案 0 :(得分:2)
抱歉,我无法重现这个。这是ij
中的快速会话:
ij> create table "APP".REGISTRATION
> (
> id INTEGER generated by default as identity (start with 1, increment by 1) not null primary key,
> firstname VARCHAR(50),
> lastname VARCHAR(50),
> username VARCHAR(50),
> password VARCHAR(50),
> email VARCHAR(50)
> );
0 rows inserted/updated/deleted
ij> insert into "APP".registration (firstname, lastname, username, password, email) values ('susheel', 'singh', 'susheel61', 'password', 'test@gmail.com');
1 row inserted/updated/deleted
ij> select * from REGISTRATION where USERNAME='susheel61';
ID |FIRSTNAME |LASTNAME |USERNAME |PASSWORD |EMAIL
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1 |susheel |singh |susheel61 |password |test@gmail.com
1 row selected
ij>
请注意,我必须更改您的CREATE TABLE
语句才能创建表格。您问题中的CREATE TABLE
声明无效;当我尝试运行它时,我收到'语法错误'。
编辑:既然您已经提供了用于创建表格的实际SQL脚本,我可以解释其中的区别。
不同之处在于您已在列名称周围指定了双引号。这样做会使列名称区分大小写。然后,在查询表时必须使用双引号,除非列名都是大写的。如果您没有在名称周围指定双引号,则会将该名称视为全部大写。
以下是如何查询最初指定的表:
ij> create table "APP".REGISTRATION
> (
> "id" INT not null primary key GENERATED ALWAYS AS IDENTITY(START WITH 1,INCREMENT BY 1),
> "firstname" VARCHAR(50),
> "lastname" VARCHAR(50),
> "username" VARCHAR(50),
> "password" VARCHAR(50),
> "email" VARCHAR(50)
> );
0 rows inserted/updated/deleted
ij> select * from "APP".registration where username = 'susheel61';
ERROR 42X04: Column 'USERNAME' is either not in any table in the FROM list or appears within a join specification and is outside the scope of the join specification or appears in a HAVING clause and is not in the GROUP BY list. If this is a CREATE or ALTER TABLE statement then 'USERNAME' is not a column in the target table.
ij> select * from "APP".registration where "username" = 'susheel61';
id |firstname |lastname |username |password |email
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
0 rows selected
ij>
(这次我没有费心插入任何数据,但希望你仍然应该明白:查询完成没有错误。)
请注意,这次列标题是小写的,而上面输出的第一部分中的列标题是大写的。
答案 1 :(得分:1)
在我的情况下发生此错误是因为我在WHERE语句中使用双引号而不是单引号
答案 2 :(得分:0)
这是我用来创建注册表的脚本,它已成功创建,但在查询具有where条件的表时遇到了问题。
create table "APP".REGISTRATION
(
"id" INT not null primary key GENERATED ALWAYS AS IDENTITY(START WITH 1,INCREMENT BY 1),
"firstname" VARCHAR(50),
"lastname" VARCHAR(50),
"username" VARCHAR(50),
"password" VARCHAR(50),
"email" VARCHAR(50)
);
现在我将其更改为此语法以创建表格,一切正常。 不确定原因。
create table "APP".REGISTRATION
(
id INTEGER generated by default as identity (start with 1, increment by 1) not null primary key,
firstname VARCHAR(50),
lastname VARCHAR(50),
username VARCHAR(50),
password VARCHAR(50),
email VARCHAR(50) unique
);
答案 3 :(得分:0)
我无法获得该表的create语句,而describe表并没有说明我的问题,但是我必须用双引号将所有表名和列名括起来,并用单引号将值括起来。
SELECT "name" FROM "THING_TABLE" WHERE "name"='Environments';
有趣的是,当我使用ID列时,我不需要引号。邓诺为什么。
可能是创建表的方式。上面说单引号表示表名区分大小写?