Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sqlite : ambiguous column name

I'm a newbie and i try to do that on my database

SELECT id FROM import a INNER JOIN import b ON a.id-1 =b.id AND b.val =0 WHERE a.val=-1

Pb : ambiguous column name: id

My table :

CREATE TABLE "import" (
    "id" INTEGER PRIMARY KEY  NOT NULL ,
    "id_analyse" integer, 
    "cross" varchar,
    "date" datetime,
    "close" double,
    "low" double,
    "high" double,
    "T" integer DEFAULT (NULL) ,
    "B" INTEGER
 )

I can't understand because i read

When more than one table is used (in a JOIN for example) there may be two columns with the same name.

And i use only one table !

is there somebody who can help me ?

stephane

like image 930
user3459402 Avatar asked Mar 25 '14 11:03

user3459402


People also ask

How do you fix ambiguous column name?

One of the simplest ways to solve an “ambiguous name column” error — without changing column name — is to give the tables you want to join an alias. This sends a clear information to the SQL Machine the columns are different.

What is ambiguous column name?

One common error when performing SQL joins is the “ambiguous column name” error. This type of error occurs when you attempt to join in two or more tables and more than one column of the same name appears in more than one of the tables.

What is ambiguous error?

Ambiguity errors occur when erasure causes two seemingly distinct generic declarations to resolve to the same erased type, causing a conflict.

Can we create two columns with same name in a relational table?

You cannot create two columns with exactly the same name.


2 Answers

Just specify which id you want to select, e.g

SELECT a.id ....

Also your table does not seem to have the val column you're using later in the query.

like image 84
laalto Avatar answered Sep 17 '22 13:09

laalto


You are actually using two tables in your query, not one, although they both get their data from the same underlying physical table. The tables are called a and b. In this particular query it doesn't matter whether you do SELECT a.id or SELECT b.id because the values are always the same. But imagine you wrote ON a.id = b.id + 1 -- in that it would make a difference whether you SELECTed the id column from a or b.

like image 45
Larry Lustig Avatar answered Sep 16 '22 13:09

Larry Lustig