6

# 1271 - Illegal Snack Combination for Operation 'UNION'

 2 years ago
source link: https://www.codesd.com/item/1271-illegal-snack-combination-for-operation-union.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

# 1271 - Illegal Snack Combination for Operation 'UNION'

advertisements
SELECT tbl_town.area_id,
       tbl_town.area_name
FROM tbl_town
WHERE city_id = 1    

UNION 

SELECT CONCAT( tbl_town.area_id, '-', tbl_town_phase.town_phase_id ),
       CONCAT( tbl_town.area_name, '-', tbl_town_phase.town_phase_name )
FROM tbl_town, tbl_town_phase
WHERE tbl_town.area_id = tbl_town_phase.town_id
AND tbl_town.city_id = 1    

UNION 

SELECT CONCAT( tbl_town.area_id, '-', tbl_town_phase.town_phase_id, '-', tbl_town_block.town_block_id ),
       CONCAT( tbl_town.area_name, '-', tbl_town_phase.town_phase_name, '-', tbl_town_block.town_block_name )
FROM tbl_town, tbl_town_phase, tbl_town_block
WHERE tbl_town.area_id = tbl_town_phase.town_id
AND tbl_town_phase.town_phase_id = tbl_town_block.town_phase_id
AND tbl_town.city_id =1
LIMIT 0 , 30

MySQL said: Documentation

#1271 - Illegal mix of collations for operation 'UNION


I have had a similar problem in the past. It's caused by mix of collations, most likely cause by differing column collations or default collation for strings.

This is what you you can try

  • check that the collation is the same for all columns
  • check that the collation for your database is the same as your columns
  • cast all your columns to the same collation as your database and run your script - then remove the collations in your query to find which column is causing the problem

Otherwise you query looks good.

Some small feedback on format would be to use joins for readability. Putting all your tables in your 'from' sections and then linking everything in the where clause can get confusing.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK