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 8507819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:58:38+00:00 2026-06-11T02:58:38+00:00

So I am trying to write a query where I get the column information

  • 0

So I am trying to write a query where I get the column information from a query
this is what i tried:

Select login from TableName AS alias_name

SELECT COLUMN_NAME,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,IS_NULLABLE,COLUMN_DEFAULT,
FROM  INFORMATION_SCHEMA.COLUMNS  WHERE TABLE_Name = 'alias_name' ORDER BY ORDINAL_POSITION ASC;

…
this doesn’t work because the query is not saved as a temporary table or what not
…

so I need the functionally of the two queries above combined into one query
thanks

  • 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-06-11T02:58:40+00:00Added an answer on June 11, 2026 at 2:58 am

    This is not possible; not in pure SQL. This is not a property of MySQL – other RDBMS-es also do not offer query metadata in this way.

    The closest you can get to solving this in pure SQL is to turn your query into a view, and then get the info for that view:

    CREATE OR REPLACE VIEW _query
    AS 
    SELECT login 
    FROM   TableName 
    ;
    
    SELECT *
    FROM   information_schema.COLUMNS
    WHERE  table_schema = SCHEMA()
    AND    table_name   = '_query'
    ;
    

    The problem with this approach is that view names have to be unique, so an application with multiple concurrent users has the challenge to come up with a unique name for the view. This is possible using dynamic sql:

    SET @name = CONCAT(_query, connection_id())
    ,   @stmt = CONCAT(
            ' CREATE VIEW '
        ,   @name
        ,   ' AS SELECT login FROM Tablename'
        )
    ; 
    
    PREPARE stmt FROM @stmt;
    EXECUTE stmt;
    DEALLOCATE PREPARE stmt;
    
    SELECT *
    FROM   information_schema.columns
    WHERE  table_schema = schema()
    AND    table_name = @name
    ;
    

    Finally, you should probably clean up your view afterwards:

    SET @stmt = CONCAT('DROP VIEW ', @name); 
    PREPARE stmt FROM @stmt;
    EXECUTE stmt;
    DEALLOCATE PREPARE stmt;
    

    The question is, why do you need this inside SQL? Typically, resultset metadata is available in SQL clients – typically the driver or client library provides this as you prepare a SQL statement. For instance in JDBC http://docs.oracle.com/javase/6/docs/api/java/sql/ResultSet.html#getMetaData()

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

Sidebar

Related Questions

I am trying to write a query that grabs information from one database and
Hi I'm trying to write a query to get information about the author, title,
I'm trying to write a sql query to the following (from this site http://sqlzoo.net/1b.htm
I am trying to write a sub query in this format listObj = session.createQuery(from
I am trying to write a query where for each day I get the
I'm trying to write a query that will return the closest match from a
I'm trying to write a query to pull some info from our database and
I am using the following query to get the count from multiple tables:- SELECT
I am trying to write a SQL query that selects multiple columns from a
I am trying to write a query to get counts of values in different

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.