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

1
  • 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. Commented Aug 13, 2017 at 6:20

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

1 Comment

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.