0

I have two tables that are in the same database. I can't seem to put a condition where it connects them somehow.

  • So here I have two tables: table1 and table2.
  • I also have columns under table1: card0, nameid
  • I also have columns under table2: equip_locations, id

  • nameid of table1 is the same as id of table2. That's why I'm trying to link them both in the query.

I want the query to find all entries in table1 that has equip_location set to 1024 in table2 then change the card0 to 0 in table1. I'm having a hard time explaining it. Anyway I tried the one below but I'm getting syntax error.

UPDATE  gc.* SET `card0` = 0
FROM    table1 AS gc 
LEFT JOIN
        table2 AS g 
ON      g.id = gc.nameid
WHERE   g.equip_locations = 1024
Shadow
  • 33,525
  • 10
  • 51
  • 64
zmt
  • 1
  • 4
  • There are similar ones to this but I wouldn't call it a duplicate especially for those in a lower level of knowledge such as myself. – zmt Aug 13 '17 at 06:20

1 Answers1

1

You are using SQL-Server syntax. MySQL is different.

UPDATE table1 AS gc 
JOIN table2 AS g ON g.id = gc.nameid
SET card0 = 0
WHERE g.equip_locations = 1024
juergen d
  • 201,996
  • 37
  • 293
  • 362
  • Thank you so much it worked like a charm. I honestly have no background in anything IT related mostly just self taught. I thought I figured it out, just to find out the syntax was a totally different thing. Thank you for pointing that out. You have no idea how much of a relief I now have. May you be blessed. – zmt Aug 13 '17 at 05:10