Automatically prefix columns with the same name in a select [duplicate] - sql

This question already has answers here:
Prefix all columns in T-SQL statement
(3 answers)
Prefix every column name with a specific string?
(1 answer)
How can I prefix all column names in a T-SQL function?
(2 answers)
Closed 3 years ago.
How could one easily select from tables that contain columns with the same name? Conflicting names in a CTE for example are not allowed. Is there a way to for example automatically rename all of the columns as TableName_ColumnName? Having to write out all of the columns just for this is very impractical.

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?

How to use WHERE clause on a field with comma seperated values in MS SQL SERVER? [duplicate]

This question already has answers here:
Filter rows by matching comma separated list against comma separated list
(3 answers)
Split String Value in SQL for Flexible Filtering
(4 answers)
Closed 1 year ago.
I have a table with a field with values stored in the "STANDARD,ELITE,DELUXE" format. I want to find all the rows where this field contains a defined value, e.g. ELITE or ELITE,DELUXE.
How can I perform a query in MSSQL SERVER to search a value in a field like this one?
Any help would be highly appreciated.
Thank you,

How to handle a column named table in database table [duplicate]

This question already has answers here:
How to deal with SQL column names that look like SQL keywords?
(17 answers)
Syntax error due to using a reserved word as a table or column name in MySQL
(1 answer)
Are quotes around tables and columns in a MySQL query really necessary?
(4 answers)
Closed 2 years ago.
I am currently working with Joomla. I want to insert a new row into #__content_types table, but there is a column named table that is currently giving me errors.
How do I insert the data despite the name of the column 'table'?
INSERT INTO #__content_types(type_id, type_title, type_alias, table, field_mappings)
VALUES
('14','SVG Image','com_view_vv.form','{"special":{"dbtable":"#__table","key":"id","type": "Corecontent","prefix":"JTable","config":"array()"},"common":{"dbtable": "#__ucm_content","key":"ucm_id","type":"Corecontent","prefix":"JTable","config":"array()"}}', '{"common": {"core_content_item_id":"id","core_title":"name","core_alais": "alias"},"special":{"imptotal":"imptotal","impmade":"impmade","clicks": "clicks","clickurl": "clickurl","custombannercode":"custombannercode","cid":"cid","purchase_type": "purchase_type","track_impressions":"track_impressions","track_clicks":"track_clicks"}}');

PIVOT in SQL using row value as Column names [duplicate]

This question already has answers here:
How to convert rows into columns in SQL Server?
(2 answers)
Convert Rows to columns using 'Pivot' in SQL Server
(9 answers)
SQL server : Convert rows into columns
(1 answer)
Convert rows to columns in SQL
(1 answer)
Closed 2 years ago.
I have a table, say Maintable like this.
I want to view this table like this:
How can this be achieved using dynamic SQL?

How do I search the name of a table, knowing only one of the table's column name in SQL? [duplicate]

This question already has answers here:
Search an Oracle database for tables with specific column names?
(4 answers)
Closed 7 years ago.
I'm trying to find a table containing a column that I know the name to. Is there some way to do a table search using only the name of the column?
In oracle
select * from user_tab_columns where column_name= '';