Mysql: INSERT... SELECT
Tanja
- datenbank
0 Vinzenz Mai0 Tanja
hallo,
hab 2 tabellen, bei denen ich 2 felder in eine andere tabelle bringen möchte.
hierfür hab ich:
INSERT INTO orte
(zusatzinfo2,name) VALUES
(
SELECT loc_id,text_val FROM geodb_textdata WHERE text_locale="de"
)
=>
MySQL meldet:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT loc_id,text_val FROM geodb_textdata WHERE text_locale="de"
)' at line 4
teste ich SELECT loc_id,text_val FROM geodb_textdata WHERE text_locale="de" allein, gibt es keine probleme.
aber in kombination mit dem isert :(
warum?
woran könnte es liegen?
bzw. wie find ich das raus?
DANKE
Hallo Tanja,
INSERT INTO orte
(zusatzinfo2,name) VALUES
(
SELECT loc_id,text_val FROM geodb_textdata WHERE text_locale="de"
)
=>
MySQL meldet:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT loc_id,text_val FROM geodb_textdata WHERE text_locale="de"
)' at line 4
die Anweisung ist vermutlich zu anspruchsvoll für Deine MySQL-Version.
warum?
weil MySQL erst ab Version 4.1 Subselects kann.
woran könnte es liegen?
Deine MySQL-Version ist älter als 4.1
bzw. wie find ich das raus?
mit
SELECT VERSION()
Freundliche Grüße
Vinzenz
SELECT VERSION()
5.0.18
Hallo Tanja,
SELECT VERSION()
5.0.18
vergiß, was ich zuerst gepostet habe. Ein Reflex ;-)
Deine Syntax weist selbstverständlich einen Fehler auf. Schließlich verwendest Du INSERT ... SELECT. In diesem Fall sind die Klammern um die SELECT-Anweisung nicht nur überflüssig, sondern falsch. Lass sie zusammen mit VALUES weg.
INSERT INTO orte (
zusatzinfo2,
name)
SELECT
loc_id,
text_val
FROM geodb_textdata
WHERE text_locale="de"
sollte es tun.
Freundliche Grüße
Vinzenz