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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:15:23+00:00 2026-06-03T06:15:23+00:00

I have tables like changes201101 changes201102 changes201103 … changes201201 And table whichchanges which contain

  • 0

I have tables like

changes201101
changes201102
changes201103
...
changes201201

And table
whichchanges which contain rows Year and MONTH

How I can select * from changes from whichchanges?

I type this query

SET @b := SELECT CONCAT('changes',year,month) FROM whichchanges;
((((@b should contain now multiple rows of changesYearMonth)))))
SET @x := SELECT * FROM @b;
Prepare stmt FROM @b;
Prepare stmt FROM @x;
Execute stmt;

#1064 – You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘SELECT CONCAT(‘changes’,year,month) FROM changes)’ at line 1

  • 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-03T06:15:24+00:00Added an answer on June 3, 2026 at 6:15 am

    You open 1 ( and close 2 ). Remove the last:

    SELECT CONCAT('changes',year,month) FROM changes
    

    Edit

    the second statement should probably be

    SET @x := SELECT * FROM (@b) as b;
    

    That works, but not sure if that is what you want:

    SET @b := 'SELECT CONCAT(''changes'',`year`,`month`) FROM whichchanges';
    SET @x := 'SELECT * FROM (SELECT CONCAT(''changes'',`year`,`month`) FROM whichchanges) as b';
    Prepare stmt FROM @b;
    Prepare stmt FROM @x;
    Execute stmt;
    

    Edit2

    If I understood you right you are looking for that single query:

    select * from changes
    where change_column in (select distinct concat(`year`, `month`) from whichchanges)
    

    Edit3

    select @b := group_concat(concat(' select * from changes', `year`, `month`, ' union ') separator ' ') as w from whichchanges;
    set @b := left(@b, length(@b) - 6);
    
    Prepare stmt FROM @b;
    Execute stmt;
    

    SQLFiddle example

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

Sidebar

Related Questions

I have 2 tables like this: Stock Table product_id bigint(20) qty float Sales Table
I have three tables like this: Person table: person_id | name | dob --------------------------------
i have four tables like below in sql server 2008 : TABLE 1 ->
So I have two tables structured like so: CREATE TABLE #nodes(node int NOT NULL);
Hi i have tables like this : table entry : id | total_comments _____________________
I have two tables like this: TABLE user( id CHAR(100) text TEXT ) TABLE
I have Two tables like this: Table categories: columns: id, name, parent 1, Foods,
I have tables like this fake ones: data: id type month value 1 1
I have two tables like this Table Product ProductId - int <PK> ProductExpiry -
I have a tables like the following CREATE TABLE Company ( Id INT )

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.