Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SQL query is changing all names?

So i am trying to change a particular name, only the query is changing all the names.

UPDATE Team
SET Naam = 'besties'
FROM Team AS T 
INNER JOIN Gebruiker AS G ON T.GebruikerID = G.Id
WHERE (G.Gebruikersnaam = 'toppers')

The table "Team" looks like this:

The table Team

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The table "Gebruiker" looks like this
The table Gebruiker
As you can see in both rows the Name is "besties", the idea is to change the Name only at one row.

In row 1 the Name was first "toppers"

>Solution :

I’m not sure about the syntax you’re currently using, but I would write it like this. I think this more clearly conveys that you’re only updating Team, and to be exact, only the Team of any of the Gebruikers named ‘toppers’.

Instead of in you could use =, if it’s guaranteed that Gebruikersnaam is unique.

UPDATE Team T
SET T.Naam = 'besties'
WHERE
  T.GebruikerID in 
  ( SELECT G.Id 
    FROM Gebruikers G 
    WHERE G.Gebruikersnaam = 'toppers'
  )
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading