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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:18:00+00:00 2026-06-11T03:18:00+00:00

I have a mysql table which holds lots of data across multiple tables. So

  • 0

I have a mysql table which holds lots of data across multiple tables. So to get it all out, I think the best bet is to use a UNION clause, however I also want to know which table the results come from as some have multiple values and some are null.

The following sql does not appear to work but I cant see whats wrong.

 (SELECT *, `2` AS 'cat' from `2` where `recid` = 'cneta0ld00ah')
  UNION
 (SELECT *, `3` AS 'cat' from `3` where `recid` = 'cneta0ld00ah')
  UNION
 (SELECT *, `4` AS 'cat' from `4` where `recid` = 'cneta0ld00ah')
  UNION
 (SELECT *, `5` AS 'cat' from `5` where `recid` = 'cneta0ld00ah')

All Tables look something like the following are are named, 1, 2, 3, 4 etc.

 recid         | item
 -------------------------
 cneta0ld00ah  |   1
 cneta0ld00ab  |   1
 cneta0ld00ad  |   3

I cant change the name of the tables as its an import from a very old database which we are trying to convert and extract data from.

If I run it without the ‘table-name’ AS ‘cat’, then it runs fine, as soon as I try to add in the table name it throws an error saying

Unknown column '2' in 'field list'

It seems to be thinking 2 is a column name?

  • 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-11T03:18:02+00:00Added an answer on June 11, 2026 at 3:18 am

    The problem is the backticks you have around the ‘table-name’ AS ‘cat’. Backticks are for quoting table and column names, not strings. You should use single quotes instead:

     (SELECT *, '2' AS 'cat' from `2` where `recid` = 'cneta0ld00ah')
      UNION
     (SELECT *, '3' AS 'cat' from `3` where `recid` = 'cneta0ld00ah')
      UNION
     (SELECT *, '4' AS 'cat' from `4` where `recid` = 'cneta0ld00ah')
      UNION
     (SELECT *, '5' AS 'cat' from `5` where `recid` = 'cneta0ld00ah')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a main MySQL table which holds products. Any multiple fields for each
I have a mysql table , which holds data like this. Name |how_out |runs
I have a mysql table field set as time type which stores data in
I have a MySQL database table which holds 6 types of records I need
I have a table which holds the data of many seq_id. Each seq_id has
i have a MySQL table namely estimate_item which contains few columns that holds decimal
I have a table in mysql which holds the values in integers, my table
I have a MySQL table which has a product_id field (big integer) 1102330008 1102330025
I have a MYSQL-Table which stores scores. Every time a user improves a new
I have a mysql table which columns are post_id and post_msg. Now I want

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.