Column does not exist in the IN clause, but SQL runs
This will work if a table in the outer query has a column of that name. This is because column names from the outer query are available to the subquery, and you could be deliberately meaning to select an outer query column in your subquery SELECT list.
For example:
CREATE TABLE #test_main (colA integer)
CREATE TABLE #test_sub (colB integer)
-- Works, because colA is available to the sub-query from the outer query. However,
-- it's probably not what you intended to do:
SELECT * FROM #test_main WHERE colA IN (SELECT colA FROM #test_sub)
-- Doesn't work, because colC is nowhere in either query
SELECT * FROM #test_main WHERE colA IN (SELECT colC FROM #test_sub)
As Damien observes, the safest way to protect yourself from this none-too-obvious "gotcha" is to get into the habit of qualifying your column names in the subquery:
-- Doesn't work, because colA is not in table #test_sub, so at least you get
-- notified that what you were trying to do doesn't make sense.
SELECT * FROM #test_main WHERE colA IN (SELECT #test_sub.colA FROM #test_sub)
How to fix this column doesn't exist error in SQL?
You cannot use columns computed in the SELECT
clause in the WHERE
clause (in SQL, the matter is evaluated before the former).
Also, you need proper type casting to compare money and numbers.
Finally, you need to turn on aggregation to compute the number of sales that satisfy the condition.
Assuming that you are using Postgres, that would be:
select count(*)
from sales
where total::numeric <> btl_price::numeric * btl_quantity
sql statement error: column .. does not exist
No, the column FK_Numbers_id
does not exist, only a column "FK_Numbers_id"
exists
Apparently you created the table using double quotes and therefor all column names are now case-sensitive and you have to use double quotes all the time:
select sim.id as idsim,
num.id as idnum
from main_sim sim
left join main_number num on ("FK_Numbers_id" = num.id);
To recap what is already documented in the manual:
The column foo
and FOO
are identical, the columns "foo"
and "FOO"
are not.
PostgreSQL Column does not exist but it actually does
Try to take it into double quotes - like "Continent"
in the query:
SELECT "Continent"
FROM network.countries
...
Postgresql Column Doesn't Exist
if you really have a camel case in you column name then you must wrap the column name with double quote
SELECT "CntrctTrmntnInd" FROM return_part_i LIMIT 10;
PostgreSQL columns (object) name are case sensitive when specified with double quotes. Unquoted identifiers are automatically used as lowercase so the correct case sequence must be write with double quotes
and as correctly suggested by Raymond Nijland if you want a LIMIT in result you should use an order by
SELECT "CntrctTrmntnInd" FROM return_part_i ORDER BY "CntrctTrmntnInd" LIMIT 10;
Where clause error : column does not exist
Try this:
curs.execute("SELECT id FROM school WHERE hisname = %s", (name,))
Related Topics
Crosstab with a Large or Undefined Number of Categories
How to Use Parameters with Rpostgresql (To Insert Data)
SQL Server: Replace Invalid Xml Characters from a Varchar(Max) Field
How to Create Daylight Savings Time Start and End Function in SQL Server
Adding 'Go' Statements to Entity Framework Migrations
Space Used by Nulls in Database
How to Pivot Dynamically with Date as Column
Can't Create Stored Procedure with Table Output Parameter
Returning Result Even for Elements in In List That Don't Exist in Table
Where Should I Start with My Opc-Ua Client
How to Get the Actual Stored Procedure Line Number from an Error Message
In SQL Server, When Should You Use Go and When Should You Use Semi-Colon ;
Case .. When Expression in Oracle SQL
How to Calculate an Exponential Moving Average on Postgres
Bulk Insert into Oracle Database: Which Is Better: for Cursor Loop or a Simple Select