SQL Select AS not being recognized as column [duplicate] - sql

This question already has answers here:
Referring to a Column Alias in a WHERE Clause
(9 answers)
Closed 1 year ago.
I am using a simple select statement and creating a column using a CONCAT function and labeling the column as Filter.
Why is the new column not being recognized?
Error message states
Invalid Column Name - Filter

You can't refer to column aliases in the where clause as the where is processed before the alias is materialised.
There are several workarounds, and assuming SQL Server you can do
select *
from table t
cross apply (values(concat(columna,columnb)))c([filter])
where [filter]='something'
Also note that the performance won't be great on large data sets since this criteria is non-sargable

Related

When do we use double quotes for table names in SQL? [duplicate]

This question already has answers here:
When do Postgres column or table names need quotes and when don't they?
(2 answers)
Are PostgreSQL column names case-sensitive?
(5 answers)
Closed 3 months ago.
A SQL coding challenge provided a database; every table was accessible when passed as a string using double quotes and not when passed as a word as I am normally used to.
This did not work:
SELECT * FROM Athletes;
Error message: relation does not exist.
But this worked and I don't understand why:
SELECT * FROM "Athletes";
Was this defined during the database creation? Or is this from PostgreSQL?

Access SQL to Firebird SQL [duplicate]

This question already has answers here:
How to select data from non-table in Firebird?
(1 answer)
Use Alias in Select Query
(3 answers)
Use column alias in same select [duplicate]
(2 answers)
Closed 11 months ago.
I have in my Access .mdb
SELECT a * b AS c, c * d AS e
I must translate this clause to Firebird.
Any hint?
Using SELECT without a FROM clause is non-standard in the SQL language. A few implementations allow it (e.g. Microsoft Access, SQL Server, and MySQL), but others do not.
Firebird is one of those that implement standard SQL, so you must provide a FROM clause, and reference a table with at least one row, or else you get no result.
http://www.firebirdfaq.org/faq30/ says:
You can use the RDB$DATABASE which is a single-row table, and part of each database's metadata:
select current_timestamp from RDB$DATABASE;
Any other table with at least one row could be used, but the point is that RDB$DATABASE is sure to be present.

How to use keyword in Postgres namespace? [duplicate]

This question already has answers here:
Escaping keyword-like column names in Postgres
(3 answers)
Not able to create the specific column in Postgres
(1 answer)
Postgresql: literal table names
(1 answer)
Closed 1 year ago.
I have a Postgres db. The tables are each in separate namespaces, which are named using two character state codes. The problem is this: for the state Indiana, the state code is "in". I am trying to execute this query:
SELECT city_name
FROM in.places
But I keep getting an error complaining about the 'in', presumably because there is a reserved keyword IN. How can I query the tables inside the 'in' namespace?

To see whether a column of a table is been used somewhere in the database [duplicate]

This question already has answers here:
How can we figure out that a column in my oracle table is being populated/updated by a trigger of another table?
(3 answers)
Closed 5 years ago.
How to check whether a particular column of a table is used in any other object or not in Oracle? For example I have a table EMPLOYEE which has a column BONUS. I need to check whether this column of this table is been used by any other objects like View, Package etc in the database.
You can try the following SQL to check for the table and column used within the object definition
SELECT 1
FROM all_source
WHERE type IN ('PROCEDURE','PACKAGE BODY','FUNCTION')
AND text LIKE '%EMPLOYEE%'
AND text LIKE '%BONUS%';

how to concatenate more than two columns in plsql developer? [duplicate]

This question already has answers here:
Oracle SQL, concatenate multiple columns + add text
(6 answers)
Closed 7 years ago.
when I run the below query
select concat(column1,column2,column3) as concatcolumn from table
I get an error "ORA-00909:INVALID NUMBER OF ARGUMENTS"
Concat only takes two arguments.
See: http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions026.htm
Use the concatenation operator:
select column1 || column2 || column3 ...
select ([column1]+','+[column2]+','+[column3]) as concatcolumn from table
Try above the query.it may changes on different type of column data type.