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

  • Home
  • SEARCH
  • 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 9123751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:25:03+00:00 2026-06-17T06:25:03+00:00

I need to select data from two different tables to create a history/ archive

  • 0

I need to select data from two different tables to create a history/ archive for my website like this:

2012

  • August(6)
  • September(4)
  • October(2)

I’m aware that there is a question similar to this in stackoverflow: PHP MYSQL Blog Archive Menu by Year and Month

However, I have two similar yet different tables.

I have tried using this example: mysql select data from two tables and different structure, but I always get the error of “#1271 – Illegal mix of collations for operation ‘UNION'”

Is there any other ways that I can combine to get my data like above?

My two tables’ fields and structures are:

1) news

  • id (int 5)
  • title (varchar 200)
  • content (text)
  • date_added (datetime)

2) equipment

  • id (int 5)
  • title (varchar 45)
  • content (varchar 250)
  • date_added (date)

Note: The tables’ id are their own individual id for the article. My tables haven nothing in common with each other.

  • 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-17T06:25:05+00:00Added an answer on June 17, 2026 at 6:25 am

    At first I thought the data types were the issue and you needed to cast the types to match:

    SELECT id, title, content, cast(date_added as Date) FROM NEWS
    UNION ALL 
    SELECT id, title, cast(content as text), date_added FROM EQUIPMENT;
    

    However when I tried it out myself I found all types converted implicitly. I took another look at your description and delved deeper into the collation issue. It’s my belief that the content column in the news table is either a different character set and/or a different collation type from the content column in the Equipment table. This could be true for the title columns or the whole tables. You need to try converting. I would suggest this:

    SELECT 
      id, 
      convert(title using utf8) collate utf8_bin, 
      convert(content using utf8) collate utf8_bin, 
      date_added 
    FROM 
      NEWS
    UNION ALL
    
    SELECT 
      id, 
      convert(title using utf8) collate utf8_bin, 
      convert(content using utf8) collate utf8_bin, 
      date_added 
    FROM 
      EQUIPMENT;
    

    That should solve your problem.

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

Sidebar

Related Questions

I need to select data from 2 tables in my DB - comments and
I select data from several tables. Then i need to edit the data returned
I am using ActiveRecord in Rails 3 to pull data from two different tables
I have two tables, SELECT [SHADOW_ID] ,[DATA] ,[TSN] ,[HEALTH_PLAN_CATEGORY_VALUE_ID] FROM [stbl834] and SELECT [HEALTH_PLAN_CATEGORY_VALUE_ID]
I have two tables that have data that I need a count from Login
I need to compare the final balances of two tables from different clients grouped
I need to get data from 3 different tables. I know the basics about
I'm trying to preform a SELECT query that grabs data from two tables only
I need to select data from one table and insert it into another table.
I am using SQL Server 2008 and I need to select all data from

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.