Get alias name dynamically in Postgresql - sql

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)

Related

Get column names stored in a different table

I have a table that has just a code for the individual column name like "A1G", "Z8H" etc.
This table is a really huge table. Therefore it would not help to manually add the alias name in the SELECT Statement like.
The description for each column code is stored in a different table:
Now I would like to SELECT * from the first table but with the right column header name.
This is stored in the second table within the filters Schema = 'ABC' and Table = 'A'.
That would be desired output:
How would you do that in SQL?
How can I change the column name?
You would be better off just creating a view with all the columns aliased to your preferred names. Once that's done you can select from the view and get the data back with the headings you want.
Look into Inner Join
Or Left Join.

SQL column name is same as Its function name

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.

Teradata Character Column with non alphabet values

I have a name column in Teradata that has customer full name all in one column. There are some names with -,_,.,/,#,! in between the name characters. I want to be able to pull records where there are names with these conditions. Is there a better option to pull records with the scenario below?
Currently, I am writing query like this
SELECT NAME FROM TABLESOURCE WHERE NAME LIKE ANY('%-%','%.%','%#%','%~%','%!%')
Thanks in advance.
I haven't tested this but I think you could test for equality when those characters are removed from the name using otranslate
select name
from tablesource
where name <> otranslate(name,'-.#~!','')

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;

like within query

I am using vs 2010 and want to perform a query on sql server database. But i have a problem i want to retrieves a row on the basis of name which i want to retrieves it using second character of name that is i don't know the first character that is for example the name is nik as i enter i it will retrives a record which having nik as value of name column.
Can any one guided me...I know following query what things i have to modified in it.
select * from table1 where name like '"& n % &"'
for example the name is nik as I enter i it will retrives a record which having nik as value of name column
try
select * from table1 where name like '_i%'
TSQL Like