K
K
Ku kuruza2016-02-02 21:56:02
MySQL
Ku kuruza, 2016-02-02 21:56:02

How to merge two text columns into one?

There are two tables consisting of columns:
id, sDate, title
id,sDate,message
having the same data types:
Int, timestamp, text
If joined by id or sDate using the query
SELECT sDate as t FROM `tb1`
UNION ALL SELECT sDate as t FROM `tb2` then everything
works fine . UNION'" Now the question is how to combine two text columns from different tables into one?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Aleksey Ratnikov, 2016-02-02
@kykyruza

If you do not want (or do not have the opportunity) to change the collation of columns, include them in the query:

SELECT
    cast(title as VARCHAR(200) CHARACTER SET utf8) COLLATE utf8_general_ci as t
  FROM `tb1`
  UNION ALL
  SELECT cast(message as varchar(200) CHARACTER SET utf8) COLLATE utf8_general_ci as t 
  FROM `tb2`

M
maximw, 2016-02-02
@maximw

MySQL says what the error is.
Do the title and message columns have the same collations?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question