Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 298909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:46:29+00:00 2026-05-12T06:46:29+00:00

i have a column named name which is present in all tables in mysql

  • 0

i have a column named “name” which is present in all tables in mysql database.

I wanted to list all the names in all tables so i used the following query

select name from (SELECT table_name FROM information_schema.tables WHERE table_type='BASE TABLE') as abc

But it did not work for me and instead it returned me the table_name column alone.

Then i used show tables and stored the output in another table called table_list then i executed the following query

select name from (select table_name from table_list) as abc

This also returned me the same result i.e. all table names.

Can i know what is that i am doing wrong and what is the right way to do it?

I am using MySQL 5.4 and i want to either write a subquery or a procedure or a function purely in mysql.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T06:46:29+00:00Added an answer on May 12, 2026 at 6:46 am

    What you need is a way to have variables in SQL (so you can say select * from $name where $name in (select ...)). SQL doesn’t allow that.

    My suggestion is to split the process up:

    First run this query:

    select 'select distinct name from ' || table_name || ' union'
    from select table_name from table_list
    

    That’ll give you the selects to run. Put them into a small script, remove the last “union” and run that script.

    [EDIT] If MySQL supports an “eval” operator in stored procedures (i.e. where you can build SQL from parts and then run it), you could do this. I checked the docs and it doesn’t look like there is an eval. You could also write an extension in C (see chapter 22) that either implements the lookup or an “eval” function.

    But my guess is that your database won’t change all the time. So the most simple solution would be to write a small SQL script that creates the code for a view (that is a string; it doesn’t actually create the view ). Every time the DB changes, you simply run the script to recreate the view and afterwards, you can run the query against the view to get a list of all names.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table named categories, which contains ID(long), Name(varchar(50)), parentID(long), and shownByDefault(boolean) columns.
I have an entity which has an ID field: @Id @Column(name = `U##ID_VOIE`) @GeneratedValue(generator
I have tables named Contact and Address and both of them have ModifiedDate column.
I have a LINQ to SQL generated class with a readonly property: <Column(Name:=totalLogins, Storage:=_TotalLogins,
I have a DataTable with a Name column. I want to generate a collection
MS SQL Server 2000 I have a column in Table A called Name. I
I have this XML in a column in my table: <keywords> <keyword name=First Name
I have a table that has a column which holds the id of a
I have a table which is referenced by foreign keys on many other tables.
I'm currently debugging a huge MySql call which joins a large amount of tables

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.