-2

I want to update a table's all columns values from another table, but it doesn't work.

I get this syntax error:

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'FROM silinecek s WHERE frameworkcode IN ('AR','CF','FA','IR','KT','SER','SF','SR' at line 3

This is my query

UPDATE marc_subfield_structure 
SET liblibrarian = s.liblibrarian, libopac = s.libopac,
    repeatable = s.repeatable, mandatory = s.mandatory,
    kohafield = s.kohafield, tab = s.tab,
    authorised_value = s.authorised_value, authtypecode = s.authtypecode,
    value_builder = s.value_builder, isurl = s.isurl, hidden = s.hidden,
    seealso = s.seealso, link = s.link, defaultvalue = s.defaultvalue,
    maxlength = s.maxlength 
FROM 
    silinecek s 
WHERE 
    frameworkcode IN ('AR','CF','FA','IR','KT','SER','SF','SR','VR')
    AND tagfield='952';

What should I do?

13
  • Does it run but not do what you want it to do? And how are the 2 tables related? I don't see any join condition. Aug 19, 2015 at 8:27
  • Add a join between the 2 tables. Like I said it will only work when for every row in marc_subfield_structure that you want to update you get exactly 1 row from silinecek.
    – Marco
    Aug 19, 2015 at 8:35
  • 1
    @Marco Allright, I wrote sql with "Join", it looks very long query because I select limit 1 and there are much columns but it works. thanks
    – Melih
    Aug 19, 2015 at 8:46
  • 2 tables are same tables.. I create silinecek as "create table silinecek select * from marc_subfield_structure Where tagfield=952;
    – Melih
    Aug 19, 2015 at 8:47
  • Is the marc_subfield_structure empty? Aug 19, 2015 at 8:48

2 Answers 2

3

The MySQL syntax for multi-table updates does not contain a FROM clause. Therefore MySQL raises an error message and tells you that the the error is near the FROM clause and that you should check the manual.

Your statement should be something like:

UPDATE 
  marc_subfield_structure m 
JOIN
  silinecek s ON m.something=s.something
SET 
    m.liblibrarian=s.liblibrarian, 
    m.libopac=s.libopac,
    m.repeatable=s.repeatable, 
    m.mandatory=s.mandatory,
    m.kohafield=s.kohafield, 
    m.tab=s.tab,
    m.authorised_value=s.authorised_value, 
    m.authtypecode=s.authtypecode,
    m.value_builder=s.value_builder, 
    m.isurl=s.isurl, 
    m.hidden=s.hidden,
    m.seealso=s.seealso, 
    m.link=s.link,
    m.defaultvalue=s.defaultvalue,
    m.maxlength=s.maxlength 
WHERE s.frameworkcode IN ('AR','CF','FA','IR','KT','SER','SF','SR','VR')
AND s.tagfield='952';

But I don't know either the structure of your tables or the purpose of your query, so that is just to give you the idea about the correct syntax.

0
0

You (can) get multiple rows from silinecek. This is not correct you must make sure that you get one and only one row. This you get by adding a join between the 2 tables.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.