SQL column name is same as Its function name - sql

There is some Data in the MySQL Workbench. Column name is Left , Right in one table .
Select PersonNumber,Left,Right,PhotoNumbr from Person.
This query is showing is error.
How can I fetch these records ,One thing cannot change column name in table.

Escape in square brackets the column names which are coincident with SQL Server functions:
SELECT PersonNumber, [Left], [Right], PhotoNumbr
FROM Person;
For future reference, do not name your columns using keyword or function names.

Related

BigQuery : How to pass a column name that has the same name as an SQL insturction

Helllo,
I have a table that has an SQL instruction as a column name. I have tried the standard SQL solutions with "limit" or [limit] but they don't work.
SELECT
limit
FROM
table
Regards
To use reserved SQL instruction words as column name, use them in backticks. Or write the table name in front:
select tbl.limit, `limit`
from
(select 1 as `limit`) tbl

Select columnName,* from table

I am a newbie in Oracle SQL, though I have experience in SQL Server.
In SQL Server, to select the rows from a table with a particular column in front:
select columnName,* from tableName
In Oracle:
select columnName,* from tableName
gives error ORA-00936: missing expression, as below:
Please guide.
I can't view images, but here's what I think you need:
select t.column_name, t.*
from table_name t
i.e. you should prefix that particular column name with a table alias ("t"), and then use the same alias with the asterisk ("t.*") to retrieve all table columns.
In Oracle, if you need to view a column but also all columns, you need to define an alias for the table.
Select columnName, A.*
from tableName A;
few things we need to keep it in mind
Alias name in sql - used to derive the individual column name via select query
When you are going to use *[select all] you don't have to worry about the alias name
But when you try to pull all the columns and some specific fields you want to filter then you should go for "Alias"
Alias its object key to refer the inter column
select stu.studentName,stu.* from student stu;

How to get column names in camelcase in Oracle SQL developer

I am trying to run few queries on Oracle SQL developer
e.g
Select name AS CandidateName, age AS CandidateAge
from tbl_candidate_details
order by candidate_id desc
But In the result I am getting the column names as "CANDIDATENAME" AND "CANDIDATEAGE".
Is there a way where I can get this as camelcase characters what I have given in the select statement("CandidateName" and "CandidateAge") ?
If the column aliases are wrapped in double-quotes, SQL Developer will use those exact values as the column names in the query results:
SELECT name AS "CandidateName", age AS "CandidateAge"
FROM tbl_candidate_details
ORDER BY candidate_id DESC;
Otherwise, the column names in the query results are always displayed in upper case
SQL is case insensitive and the SQL standard requires to fold all un-quoted identifiers to uppercase. If you want to preserve the case of your identifiers you need to quote them:
Select name AS "CandidateName",
age AS "CandidateAge"
from tbl_candidate_details
order by candidate_id desc

SQL case unsensitive

Hello i have a table with colums called NAME, in this colum i can have this type of name : First name Uppercase and other lower (Jack), all name uppercase (JACK), and name with space (Jack ) or (JACK ).
How can show all name than have jack in all type ?
i need to search multiple name with IN statement
i use ORACLE
Assuming SQL Server:
SELECT Name FROM Table WHERE Name LIKE '%jack%'
SELECT Name
FROM Table
WHERE UPPER(Name) LIKE '%JACK%'
will work in all SQL. In SQL Server I believe LIKE is case insensitive but it might depend on configuration settings and collation.
or maybe you need
SELECT Name
FROM Table
WHERE UPPER(TRIM(Name)) IN ('JACK','HOGAN','VICTOR')
(replace TRIM(Name) with RTRIM(LTRIM(Name)) if not using SQL Server.)
If you have a table with the list of names you can do it like this:
SELECT Name
FROM Table
JOIN NameTable ON UPPER(RTRIM(LTRIM(Table.Name))) = NameTable.Name

Get alias name dynamically in Postgresql

I have one table named tblalias.which is having two columns cid, description
cid description
1 Employee
2 Join Date
3 Retire Date
Like this three record is present
Now I have another table tblemployee. I want to write a query for tblemployee to get record but alias name for that query I want should come from tblalias
select nama as Employee,
joindate as "Join Date",
retiredate as "Retire Date"
from tblemployee
If I change value is tblalias table to my select query should return new value as alias is it possible if yes how please help me
The only way to do this is with dynamic SQL. First fetch the alias names then build the final SQL and execute it.
There is no way doing this with a single "hardcoded" statement.
If you want spaces in names you should quote them. (spaces in names is generally a bad Idea, but that's another matter)