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.
At first I thought the data types were the issue and you needed to cast the types to match:
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
contentcolumn in thenewstable is either a different character set and/or a different collation type from thecontentcolumn in theEquipmenttable. This could be true for the title columns or the whole tables. You need to try converting. I would suggest this:That should solve your problem.