-2

I have some trouble trying to get column values from a table to a different table.

I got a table called sorting_orders and a table thats called new_tags and theres a column in sorting_orders thats called orders. Theres also a column in sorting_orders with IDS that match with the IDS from new_tags.

What i need is to get all the values from the column "orders" to a column in new_tags which is called "sorting" while the IDS are matching from both tables.

I tried various querys but usually i get a warning message that says several fields dont have a default value. After I got this warning my entire table went empty except the sorting column.

INSERT INTO new__tags(sorting) SELECT orders FROM sorting_orders the warning i get is Field X doesn't have a default value. after this it just sets it to null while it had a value before

Thank you very much, I appreciate any help.

kerv
  • 315
  • 1
  • 2
  • 13
  • 1
    Please show the query you've tried. – KiwiJuicer May 11 '16 at 13:49
  • 2
    @kerv then you are using the wrong place on the internet. please visit http://www.google.com and try again! – low_rents May 11 '16 at 13:51
  • http://stackoverflow.com/questions/5391344/insert-with-select – KiwiJuicer May 11 '16 at 13:52
  • 1
    "I tried various querys but usually i get a warning message" Show the query and the message. – Tab Alleman May 11 '16 at 13:52
  • INSERT INTO new__tags(sorting) SELECT orders FROM sorting_orders the warning i get is Field X doesn't have a default value. after this it just sets it to null while it had a value before. – kerv May 11 '16 at 13:55
  • http://stackoverflow.com/help/asking and http://stackoverflow.com/help/mcve – MatBailie May 11 '16 at 13:55
  • @low_rents Did you even read the question? I have difficulties with creating an SQL query. Not with any code.... – kerv May 11 '16 at 13:59
  • 1
    @kerv well, I did - and you know for sure that you have to try coding yourself and paste what you have tried when asking a question here on SO. and the text used to write SQL queries is considered being **code**. – low_rents May 11 '16 at 14:02
  • @low_rents Ok, I edited my question. Hopefully its more clear now. – kerv May 11 '16 at 14:03
  • @KiwiJuicer I have tried this but i get the warning Field X doesn't have a default value, then it creates a new empty row with nothing in it and the intended row stayed the same. – kerv May 11 '16 at 14:08
  • Show your code please. – KiwiJuicer May 11 '16 at 14:10
  • @KiwiJuicer INSERT INTO new__tags (sorting) SELECT `orders` FROM sorting_orders WHERE id = 458; – kerv May 11 '16 at 14:11

1 Answers1

0

You are looking for an update by select.

Use this as example:

UPDATE new__tags nt, (SELECT orders FROM sorting_orders so where so.id = 458) src 
  SET nt.sorting = src.orders where nt.id = 458 ;
KiwiJuicer
  • 1,952
  • 14
  • 28