gaurav singh
gaurav singh

Reputation: 1

select Query from a table and plus table name as a column

I am trying to make a select query where i select all the columns from a table and add the table name as another column.but i don't know how to proceed with this.

SELECT t.name , t.table_name FROM `glassfilms` as t WHERE `name` LIKE '%007%' 

here t.table_name is not a column. I need the columns name and table_name

Upvotes: 0

Views: 161

Answers (1)

Bhomit Davara
Bhomit Davara

Reputation: 21

From my concern, it is not a good idea to get a table name with the select statement because you have to add your database name and tables name which has confidential data for your project.

By the way, I solved your problem with the below query.

SELECT t.name, 
  (select table_name from information_schema.tables where TABLE_SCHEMA = '{{your_database_name}}' and table_name = 'glassfilms') as tbl_name 
FROM glassfilms t 
WHERE t.name like "%007%";

Upvotes: 1

Related Questions