问题与WHERE条件Derby数据库

问题描述 投票:0回答:4

下面是我的表结构。

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 protected]

现在,当我尝试查询作为

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.
java sql derby
4个回答
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', '[email protected]');
1 row inserted/updated/deleted
ij> select * from REGISTRATION where USERNAME='susheel61';
ID         |FIRSTNAME                                         |LASTNAME                                          |USERNAME               |PASSWORD                                          |EMAIL
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1          |susheel                                           |singh                                             |susheel61              |password                                          |[email protected]

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
投票

在我来说,因为我是在我的WHERE语句使用,而不是单引号的双引号发生此错误


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
);

0
投票

我不可能得到表的创建语句,以及描述表所述指示这样的事我的问题,但我不得不使用双引号的所有表和列名,并用单引号值。

SELECT "name" FROM "THING_TABLE" WHERE "name"='Environments';

有趣的是,当我使用的ID列我没有需要报价。不知道为什么。

可能是创建表的方式。上面说的单引号意味着表名称区分大小写?

© www.soinside.com 2019 - 2024. All rights reserved.