Eugene Kosov wrote:
Dennis Duggen wrote:
Hi list
Im new to the list so i hope it's the right place for my post.
For a projekt i am combining different tables. Everything seems to work,
but in some rows the "Kode" field VARCHAR(10) ends up as INT. I will try
to explain with an example.
Table1
46
47
48
67
Table2
BBEGYNDER
BVILDIVAND
01ELITE
02SSKOLEN
When i combine these i get
46
47
48
67
0
0
01
02
The desired result should be:
46
47
48
67
BBEGYNDER
BVILDIVAND
01ELITE
02SSKOLEN
According to:
http://dev.mysql.com/doc/mysql/en/union.html
coresponding columns of statements' results should have the same type.
Try to cnage order of SELECTs in your query.. I think you'll get what
you want.
Right, the type of each column is determined by the first SELECT in the UNION.
Hence, your VARCHARs are converted to INTs because they are in an INT column
based on the first SELECT. You can fix this by making that column a string
column of appropriate length. Changing the order would work:
INSERT INTO searchTemp
(
SELECT 'wesHoldKategori', wesHoldKategori.Kode AS id, Navn AS headline,
Beskrivelse AS text, '', image_id FROM wesHoldKategori
)
UNION ALL
(
SELECT 'content', id, headline, text, teaser, image_id FROM content
);
Alternatively, you could keep the same order, but change the problem column to
a string:
INSERT INTO searchTemp
(
SELECT 'content', CONCAT(id,' '), headline, text, teaser, image_id
FROM content
)
UNION ALL
(
SELECT 'wesHoldKategori', wesHoldKategori.Kode AS id, Navn AS headline,
Beskrivelse AS text, '', image_id FROM wesHoldKategori
);
Michael
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]